Skip to content

Commit 2c83842

Browse files
authoredOct 12, 2021
Fix scope resolution for TS enums (#7057)
1 parent dbe1153 commit 2c83842

File tree

3 files changed

+54
-3
lines changed

3 files changed

+54
-3
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export enum A {
2+
X = 'X',
3+
Y = 'Y',
4+
}
5+
6+
export enum B {
7+
X = 'X',
8+
Y = 'Y',
9+
}
10+
11+
export enum C {
12+
X = 'X',
13+
Y = 'Y',
14+
}
15+
16+
export const z = {
17+
a: A.X,
18+
c: C.Y,
19+
};

‎packages/core/integration-tests/test/typescript.js

+31
Original file line numberDiff line numberDiff line change
@@ -203,5 +203,36 @@ describe('typescript', function() {
203203
{config},
204204
);
205205
});
206+
207+
it('should handle compile enums correctly', async function() {
208+
if (config != null) {
209+
return;
210+
}
211+
let b = await bundle(
212+
path.join(__dirname, '/integration/typescript-enum/index.ts'),
213+
{config},
214+
);
215+
216+
let output = await run(b);
217+
218+
assert.deepEqual(output, {
219+
A: {
220+
X: 'X',
221+
Y: 'Y',
222+
},
223+
B: {
224+
X: 'X',
225+
Y: 'Y',
226+
},
227+
C: {
228+
X: 'X',
229+
Y: 'Y',
230+
},
231+
z: {
232+
a: 'X',
233+
c: 'Y',
234+
},
235+
});
236+
});
206237
}
207238
});

‎packages/transformers/js/core/src/lib.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,9 @@ pub fn transform(config: Config) -> Result<TransformResult, std::io::Error> {
253253

254254
let global_mark = Mark::fresh(Mark::root());
255255
let ignore_mark = Mark::fresh(Mark::root());
256-
module = module.fold_with(&mut resolver_with_mark(global_mark));
257-
258256
module = {
259257
let mut passes = chain!(
258+
resolver_with_mark(global_mark),
260259
Optional::new(
261260
react::react(
262261
source_map.clone(),
@@ -275,7 +274,9 @@ pub fn transform(config: Config) -> Result<TransformResult, std::io::Error> {
275274
}),
276275
config.decorators
277276
),
278-
Optional::new(typescript::strip(), config.is_type_script)
277+
Optional::new(typescript::strip(), config.is_type_script),
278+
// Run resolver again. TS pass messes things up.
279+
resolver_with_mark(global_mark),
279280
);
280281

281282
module.fold_with(&mut passes)

0 commit comments

Comments
 (0)
Please sign in to comment.