Skip to content

Commit

Permalink
Fix scope resolution for TS enums (#7057)
Browse files Browse the repository at this point in the history
  • Loading branch information
devongovett committed Oct 12, 2021
1 parent dbe1153 commit 2c83842
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
@@ -0,0 +1,19 @@
export enum A {
X = 'X',
Y = 'Y',
}

export enum B {
X = 'X',
Y = 'Y',
}

export enum C {
X = 'X',
Y = 'Y',
}

export const z = {
a: A.X,
c: C.Y,
};
31 changes: 31 additions & 0 deletions packages/core/integration-tests/test/typescript.js
Expand Up @@ -203,5 +203,36 @@ describe('typescript', function() {
{config},
);
});

it('should handle compile enums correctly', async function() {
if (config != null) {
return;
}
let b = await bundle(
path.join(__dirname, '/integration/typescript-enum/index.ts'),
{config},
);

let output = await run(b);

assert.deepEqual(output, {
A: {
X: 'X',
Y: 'Y',
},
B: {
X: 'X',
Y: 'Y',
},
C: {
X: 'X',
Y: 'Y',
},
z: {
a: 'X',
c: 'Y',
},
});
});
}
});
7 changes: 4 additions & 3 deletions packages/transformers/js/core/src/lib.rs
Expand Up @@ -253,10 +253,9 @@ pub fn transform(config: Config) -> Result<TransformResult, std::io::Error> {

let global_mark = Mark::fresh(Mark::root());
let ignore_mark = Mark::fresh(Mark::root());
module = module.fold_with(&mut resolver_with_mark(global_mark));

module = {
let mut passes = chain!(
resolver_with_mark(global_mark),
Optional::new(
react::react(
source_map.clone(),
Expand All @@ -275,7 +274,9 @@ pub fn transform(config: Config) -> Result<TransformResult, std::io::Error> {
}),
config.decorators
),
Optional::new(typescript::strip(), config.is_type_script)
Optional::new(typescript::strip(), config.is_type_script),
// Run resolver again. TS pass messes things up.
resolver_with_mark(global_mark),
);

module.fold_with(&mut passes)
Expand Down

0 comments on commit 2c83842

Please sign in to comment.