Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for JS module blocks #634

Open
alangpierce opened this issue Jul 6, 2021 · 0 comments
Open

Add support for JS module blocks #634

alangpierce opened this issue Jul 6, 2021 · 0 comments

Comments

@alangpierce
Copy link
Owner

JS module blocks is a TC39 proposal, currently stage 2, that allows multiple ES modules to be defined in the same file.

More details here: https://github.com/tc39/proposal-js-module-blocks

Example code:

let moduleBlock = module {
  export let y = 1;
};
let moduleExports = await import(moduleBlock);
assert(moduleExports.y === 1);

There are a few possible levels of supporting this syntax:

  1. Parse the code as a regular block so that Sucrase can preserve it and transform the module contents. This is coming soon as part of porting Parse JS Module Blocks proposal babel/babel#12469 . This should handle things like the JSX transform, transforming TS enums, and removing types.
  2. Update all file-wide logic to treat the module block as its own "file". This particularly comes up when determining name usage to remove type-only imports. It would also be necessary for the imports transform, though it may make sense to disallow the module syntax when transpiling to CommonJS.
  3. Transpile the module block to work in a runtime that doesn't support it. This would likely involve somehow emitting multiple files for a single input file, so it seems probably best to call it out of scope for Sucrase.

This task will track tasks 1 and 2, though if others feel strongly that Sucrase should implement 3, let me know.

alangpierce added a commit that referenced this issue Jul 6, 2021
Instructions: https://github.com/alangpierce/sucrase/wiki/Porting-changes-from-Babel's-parser

2f755ef052 v7.12.17
🚫 Release only.

16e9f1c8e5 Support Flow `this` parameter annotations (#12234)
🚫 Seems to be working already.

5b99b8f221 Flow Enums with unknown members support (#12193)
🚫 For now, Flow enums won't be supported in Sucrase.

e4588bed22 Support TypeScript 4.2 abstract constructor signatures (#12628)
✅ Ported with a similar implementation, but made a new enum value instead of passing a flag.

9c567baa9b Parse JS Module Blocks proposal (#12469)
✅ Added basic parsing support, though the transformer doesn't yet do anything special. Filed #634 as follow-up.

03d7911be6 Implement class features in estree (#12370)
🚫 Sucrase doesn't support entree.

c827193d9c v7.13.0
🚫 Release only.

c30039029a Don't enable class features by default in `estree` (#12867)
🚫 Sucrase doesn't support entree.

e940b8c4b9 v7.13.4
🚫 Release only.

b62fc3d44f babel-parser(flow): Set `this` property to `null` for FunctionTypeAnnotation without parens (#12930)
🚫 AST only.

efdca01409 fix: add tokens when tokens: true is passed to parseExpression (#12939)
🚫 Only applies to Babel-specific API.

2c0e8d0008 v7.13.9
🚫 Release only.

b416847b61 (ts) Raise syntax error for abstract methods with a body (#12687)
🚫 Validation only.

d04842a700 Avoid using CJS globals in internal source files (#12963)
🚫 Babel change not relevant for Sucrase.

d1d404b9a3 v7.13.10
🚫 Release only.

1a05b81387 Support multiple static blocks (#12738)
🚫 Only affects validation, multiple static blocks were already supported.

0988c471e9 Parse type imports in TSImportEqualsDeclaration (#12962)
✅ Implemented independently using similar logic as in Babel.
alangpierce added a commit that referenced this issue Jul 6, 2021
Instructions: https://github.com/alangpierce/sucrase/wiki/Porting-changes-from-Babel's-parser

2f755ef052 v7.12.17
🚫 Release only.

16e9f1c8e5 Support Flow `this` parameter annotations (#12234)
🚫 Seems to be working already.

5b99b8f221 Flow Enums with unknown members support (#12193)
🚫 For now, Flow enums won't be supported in Sucrase.

e4588bed22 Support TypeScript 4.2 abstract constructor signatures (#12628)
✅ Ported with a similar implementation, but made a new enum value instead of passing a flag.

9c567baa9b Parse JS Module Blocks proposal (#12469)
✅ Added basic parsing support, though the transformer doesn't yet do anything special. Filed #634 as follow-up.

03d7911be6 Implement class features in estree (#12370)
🚫 Sucrase doesn't support entree.

c827193d9c v7.13.0
🚫 Release only.

c30039029a Don't enable class features by default in `estree` (#12867)
🚫 Sucrase doesn't support entree.

e940b8c4b9 v7.13.4
🚫 Release only.

b62fc3d44f babel-parser(flow): Set `this` property to `null` for FunctionTypeAnnotation without parens (#12930)
🚫 AST only.

efdca01409 fix: add tokens when tokens: true is passed to parseExpression (#12939)
🚫 Only applies to Babel-specific API.

2c0e8d0008 v7.13.9
🚫 Release only.

b416847b61 (ts) Raise syntax error for abstract methods with a body (#12687)
🚫 Validation only.

d04842a700 Avoid using CJS globals in internal source files (#12963)
🚫 Babel change not relevant for Sucrase.

d1d404b9a3 v7.13.10
🚫 Release only.

1a05b81387 Support multiple static blocks (#12738)
🚫 Only affects validation, multiple static blocks were already supported.

0988c471e9 Parse type imports in TSImportEqualsDeclaration (#12962)
✅ Implemented independently using similar logic as in Babel.
alangpierce added a commit that referenced this issue Jan 3, 2022
Instructions: https://github.com/alangpierce/sucrase/wiki/Porting-changes-from-Babel's-parser

9bad558d13 [babel 8] Use an identifier for `TSTypeParameter.name` (#12829)
🚫 AST-only.

bfd2f8f4b1 fix: disallow computed `async`/`get`/`set` keyword (#13531)
🚫 Validation only.

8a3e0fd960 Async do expression should start at async (#13534)
🚫 AST only.

79d3276f61 Overhaul comment attachment (#13521)
🚫 AST only.

6e57617138 Fix await binding error within static block (#13088)
🚫 Only affects validation and babel-parser scopes, which aren't in Sucrase.

2c6db56696 Allow module block to start a member expression (#13573)
🚫 Module blocks aren't supported yet, tracked in #634

dd942f92af fix: parser `strictMode` option (#13548)
🚫 Option isn't relevant to Sucrase.

22b2f4fc02 Update babel-parser.d.ts (#13575)
🚫 Babel-specific types only.

e591780244 v7.14.8
🚫 Release only.

4a56387330 ts: Check if param is assignable when parsing arrow return type (#13581)
✅ Added test and implemented by re-parsing as a non-arrow-function if we get an error. Fixes #631. Fixes #666.

e4de256cdd chore: reorganize benchmarks (#13606)
🚫 Code not relevant to Sucrase.

d3a7cd5e8d Replace generic `__clone` call by specific methods (#13611)
🚫 Only affects ASTs.

aa2cac5edc v7.14.9
🚫 Release only.

b3ab4769d0 fix(ts): raise error for `export default interface {}` (#13622)
🚫 Validation only.

a254ea38a4 Enable ergonomic brand checks (`#priv in`) by default (#13554)
🚫 Already works by default in Sucrase.

6276853eb9 Add support for the "Hack" pipeline proposal (#13191)
🚫 Already works with Sucrase. This babel-parser change updates error handling (not relevant for Sucrase) and switches the default topic reference token to `%`, but more recent discussions have decided against that one.

cd4b3fbffe parser: Fix Hack/smart-pipe error positions (#13426)
🚫 AST only.

35e4e1f067 Hack-pipe proposal with `%` topic token (#13416)
🚫 Changes are only to AST, error handling, and `%` topic reference token support.

ff287ac5a5 Fix `%==` parsing in hack pipes (#13536)
🚫 Only affects outdated `%` topic reference tokens.

c35637e247 feat(ts): raise error for abstract property with initializer (#13523)
🚫 Validation only.

ddaf0d4296 Enable top-level `await` parsing by default (#13387)
🚫 Already enabled by default in Sucrase.

d5b0d9e33d Add `attachComment` parser option to disable comment attachment (#13229)
🚫 Not relevant to Sucrase.

0671afcf87 [ts] support optional chain call with generic (#13513)
🚫 Already works and has tests.

6912f968a6 v7.15.0
🚫 Release only.

f9dcc4e4bb Fix array destructuring elision parsing in TS arrow functions (#13641)
🚫 Regression that wasn't introduced in Sucrase.

e294beb3ac Add `.errors` to the `@babel/parser` return type definitions (#13653)
🚫 Type definitions only.

084870faad v7.15.2
🚫 Release only.

8a09993e39 fix(parser): add `attachComment` to `ParserOptions` type (#13657)
🚫 Type definitions only.

da1d166ea6 perf: minor tokenizer tweaks (#13652)
🚫 Optimizations not relevant to Sucrase.

9d0aa1ec9d Disallow `<T>(a => b)` when parsing Flow (#13645)
🚫 Validation only.

e721f61110 [flow] Fix parsing of arrows in conditional exprs in parens (#13655)
✅ Seems to be fixed by above fix. I added a regression test.

1229336fea Fix parse error when using named import "as" with flow parser (#13659)
✅ Added test and ported fix in fairly direct way.

9286cdb072 Re-enable disabled flow parser test (#13661)
🚫 Test only.

a5624ea457 v7.15.3
🚫 Test only.

10640b2aad perf: partially replace `.concat` with `.push` (#13609)
🚫 Sucrase doesn't use `.concat`.
alangpierce added a commit that referenced this issue Jun 22, 2022
Instructions: https://github.com/alangpierce/sucrase/wiki/Porting-changes-from-Babel's-parser

9bad558d13 [babel 8] Use an identifier for `TSTypeParameter.name` (#12829)
🚫 AST-only.

bfd2f8f4b1 fix: disallow computed `async`/`get`/`set` keyword (#13531)
🚫 Validation only.

8a3e0fd960 Async do expression should start at async (#13534)
🚫 AST only.

79d3276f61 Overhaul comment attachment (#13521)
🚫 AST only.

6e57617138 Fix await binding error within static block (#13088)
🚫 Only affects validation and babel-parser scopes, which aren't in Sucrase.

2c6db56696 Allow module block to start a member expression (#13573)
🚫 Module blocks aren't supported yet, tracked in #634

dd942f92af fix: parser `strictMode` option (#13548)
🚫 Option isn't relevant to Sucrase.

22b2f4fc02 Update babel-parser.d.ts (#13575)
🚫 Babel-specific types only.

e591780244 v7.14.8
🚫 Release only.

4a56387330 ts: Check if param is assignable when parsing arrow return type (#13581)
✅ Added test and implemented by re-parsing as a non-arrow-function if we get an error. Fixes #631. Fixes #666.

e4de256cdd chore: reorganize benchmarks (#13606)
🚫 Code not relevant to Sucrase.

d3a7cd5e8d Replace generic `__clone` call by specific methods (#13611)
🚫 Only affects ASTs.

aa2cac5edc v7.14.9
🚫 Release only.

b3ab4769d0 fix(ts): raise error for `export default interface {}` (#13622)
🚫 Validation only.

a254ea38a4 Enable ergonomic brand checks (`#priv in`) by default (#13554)
🚫 Already works by default in Sucrase.

6276853eb9 Add support for the "Hack" pipeline proposal (#13191)
🚫 Already works with Sucrase. This babel-parser change updates error handling (not relevant for Sucrase) and switches the default topic reference token to `%`, but more recent discussions have decided against that one.

cd4b3fbffe parser: Fix Hack/smart-pipe error positions (#13426)
🚫 AST only.

35e4e1f067 Hack-pipe proposal with `%` topic token (#13416)
🚫 Changes are only to AST, error handling, and `%` topic reference token support.

ff287ac5a5 Fix `%==` parsing in hack pipes (#13536)
🚫 Only affects outdated `%` topic reference tokens.

c35637e247 feat(ts): raise error for abstract property with initializer (#13523)
🚫 Validation only.

ddaf0d4296 Enable top-level `await` parsing by default (#13387)
🚫 Already enabled by default in Sucrase.

d5b0d9e33d Add `attachComment` parser option to disable comment attachment (#13229)
🚫 Not relevant to Sucrase.

0671afcf87 [ts] support optional chain call with generic (#13513)
🚫 Already works and has tests.

6912f968a6 v7.15.0
🚫 Release only.

f9dcc4e4bb Fix array destructuring elision parsing in TS arrow functions (#13641)
🚫 Regression that wasn't introduced in Sucrase.

e294beb3ac Add `.errors` to the `@babel/parser` return type definitions (#13653)
🚫 Type definitions only.

084870faad v7.15.2
🚫 Release only.

8a09993e39 fix(parser): add `attachComment` to `ParserOptions` type (#13657)
🚫 Type definitions only.

da1d166ea6 perf: minor tokenizer tweaks (#13652)
🚫 Optimizations not relevant to Sucrase.

9d0aa1ec9d Disallow `<T>(a => b)` when parsing Flow (#13645)
🚫 Validation only.

e721f61110 [flow] Fix parsing of arrows in conditional exprs in parens (#13655)
✅ Seems to be fixed by above fix. I added a regression test.

1229336fea Fix parse error when using named import "as" with flow parser (#13659)
✅ Added test and ported fix in fairly direct way.

9286cdb072 Re-enable disabled flow parser test (#13661)
🚫 Test only.

a5624ea457 v7.15.3
🚫 Test only.

10640b2aad perf: partially replace `.concat` with `.push` (#13609)
🚫 Sucrase doesn't use `.concat`.
alangpierce added a commit that referenced this issue Jun 22, 2022
Instructions: https://github.com/alangpierce/sucrase/wiki/Porting-changes-from-Babel's-parser

9bad558d13 [babel 8] Use an identifier for `TSTypeParameter.name` (#12829)
🚫 AST-only.

bfd2f8f4b1 fix: disallow computed `async`/`get`/`set` keyword (#13531)
🚫 Validation only.

8a3e0fd960 Async do expression should start at async (#13534)
🚫 AST only.

79d3276f61 Overhaul comment attachment (#13521)
🚫 AST only.

6e57617138 Fix await binding error within static block (#13088)
🚫 Only affects validation and babel-parser scopes, which aren't in Sucrase.

2c6db56696 Allow module block to start a member expression (#13573)
🚫 Module blocks aren't supported yet, tracked in #634

dd942f92af fix: parser `strictMode` option (#13548)
🚫 Option isn't relevant to Sucrase.

22b2f4fc02 Update babel-parser.d.ts (#13575)
🚫 Babel-specific types only.

e591780244 v7.14.8
🚫 Release only.

4a56387330 ts: Check if param is assignable when parsing arrow return type (#13581)
✅ Added test and implemented by re-parsing as a non-arrow-function if we get an error. Fixes #631. Fixes #666.

e4de256cdd chore: reorganize benchmarks (#13606)
🚫 Code not relevant to Sucrase.

d3a7cd5e8d Replace generic `__clone` call by specific methods (#13611)
🚫 Only affects ASTs.

aa2cac5edc v7.14.9
🚫 Release only.

b3ab4769d0 fix(ts): raise error for `export default interface {}` (#13622)
🚫 Validation only.

a254ea38a4 Enable ergonomic brand checks (`#priv in`) by default (#13554)
🚫 Already works by default in Sucrase.

6276853eb9 Add support for the "Hack" pipeline proposal (#13191)
🚫 Already works with Sucrase. This babel-parser change updates error handling (not relevant for Sucrase) and switches the default topic reference token to `%`, but more recent discussions have decided against that one.

cd4b3fbffe parser: Fix Hack/smart-pipe error positions (#13426)
🚫 AST only.

35e4e1f067 Hack-pipe proposal with `%` topic token (#13416)
🚫 Changes are only to AST, error handling, and `%` topic reference token support.

ff287ac5a5 Fix `%==` parsing in hack pipes (#13536)
🚫 Only affects outdated `%` topic reference tokens.

c35637e247 feat(ts): raise error for abstract property with initializer (#13523)
🚫 Validation only.

ddaf0d4296 Enable top-level `await` parsing by default (#13387)
🚫 Already enabled by default in Sucrase.

d5b0d9e33d Add `attachComment` parser option to disable comment attachment (#13229)
🚫 Not relevant to Sucrase.

0671afcf87 [ts] support optional chain call with generic (#13513)
🚫 Already works and has tests.

6912f968a6 v7.15.0
🚫 Release only.

f9dcc4e4bb Fix array destructuring elision parsing in TS arrow functions (#13641)
🚫 Regression that wasn't introduced in Sucrase.

e294beb3ac Add `.errors` to the `@babel/parser` return type definitions (#13653)
🚫 Type definitions only.

084870faad v7.15.2
🚫 Release only.

8a09993e39 fix(parser): add `attachComment` to `ParserOptions` type (#13657)
🚫 Type definitions only.

da1d166ea6 perf: minor tokenizer tweaks (#13652)
🚫 Optimizations not relevant to Sucrase.

9d0aa1ec9d Disallow `<T>(a => b)` when parsing Flow (#13645)
🚫 Validation only.

e721f61110 [flow] Fix parsing of arrows in conditional exprs in parens (#13655)
✅ Seems to be fixed by above fix. I added a regression test.

1229336fea Fix parse error when using named import "as" with flow parser (#13659)
✅ Added test and ported fix in fairly direct way.

9286cdb072 Re-enable disabled flow parser test (#13661)
🚫 Test only.

a5624ea457 v7.15.3
🚫 Test only.

10640b2aad perf: partially replace `.concat` with `.push` (#13609)
🚫 Sucrase doesn't use `.concat`.
1Lighty pushed a commit to Astra-mod/sucrase that referenced this issue Aug 14, 2022
)

Instructions: https://github.com/alangpierce/sucrase/wiki/Porting-changes-from-Babel's-parser

9bad558d13 [babel 8] Use an identifier for `TSTypeParameter.name` (#12829)
🚫 AST-only.

bfd2f8f4b1 fix: disallow computed `async`/`get`/`set` keyword (#13531)
🚫 Validation only.

8a3e0fd960 Async do expression should start at async (#13534)
🚫 AST only.

79d3276f61 Overhaul comment attachment (#13521)
🚫 AST only.

6e57617138 Fix await binding error within static block (#13088)
🚫 Only affects validation and babel-parser scopes, which aren't in Sucrase.

2c6db56696 Allow module block to start a member expression (#13573)
🚫 Module blocks aren't supported yet, tracked in alangpierce#634

dd942f92af fix: parser `strictMode` option (#13548)
🚫 Option isn't relevant to Sucrase.

22b2f4fc02 Update babel-parser.d.ts (#13575)
🚫 Babel-specific types only.

e591780244 v7.14.8
🚫 Release only.

4a56387330 ts: Check if param is assignable when parsing arrow return type (#13581)
✅ Added test and implemented by re-parsing as a non-arrow-function if we get an error. Fixes alangpierce#631. Fixes alangpierce#666.

e4de256cdd chore: reorganize benchmarks (#13606)
🚫 Code not relevant to Sucrase.

d3a7cd5e8d Replace generic `__clone` call by specific methods (#13611)
🚫 Only affects ASTs.

aa2cac5edc v7.14.9
🚫 Release only.

b3ab4769d0 fix(ts): raise error for `export default interface {}` (#13622)
🚫 Validation only.

a254ea38a4 Enable ergonomic brand checks (`#priv in`) by default (#13554)
🚫 Already works by default in Sucrase.

6276853eb9 Add support for the "Hack" pipeline proposal (#13191)
🚫 Already works with Sucrase. This babel-parser change updates error handling (not relevant for Sucrase) and switches the default topic reference token to `%`, but more recent discussions have decided against that one.

cd4b3fbffe parser: Fix Hack/smart-pipe error positions (#13426)
🚫 AST only.

35e4e1f067 Hack-pipe proposal with `%` topic token (#13416)
🚫 Changes are only to AST, error handling, and `%` topic reference token support.

ff287ac5a5 Fix `%==` parsing in hack pipes (#13536)
🚫 Only affects outdated `%` topic reference tokens.

c35637e247 feat(ts): raise error for abstract property with initializer (#13523)
🚫 Validation only.

ddaf0d4296 Enable top-level `await` parsing by default (#13387)
🚫 Already enabled by default in Sucrase.

d5b0d9e33d Add `attachComment` parser option to disable comment attachment (#13229)
🚫 Not relevant to Sucrase.

0671afcf87 [ts] support optional chain call with generic (#13513)
🚫 Already works and has tests.

6912f968a6 v7.15.0
🚫 Release only.

f9dcc4e4bb Fix array destructuring elision parsing in TS arrow functions (#13641)
🚫 Regression that wasn't introduced in Sucrase.

e294beb3ac Add `.errors` to the `@babel/parser` return type definitions (#13653)
🚫 Type definitions only.

084870faad v7.15.2
🚫 Release only.

8a09993e39 fix(parser): add `attachComment` to `ParserOptions` type (#13657)
🚫 Type definitions only.

da1d166ea6 perf: minor tokenizer tweaks (#13652)
🚫 Optimizations not relevant to Sucrase.

9d0aa1ec9d Disallow `<T>(a => b)` when parsing Flow (#13645)
🚫 Validation only.

e721f61110 [flow] Fix parsing of arrows in conditional exprs in parens (#13655)
✅ Seems to be fixed by above fix. I added a regression test.

1229336fea Fix parse error when using named import "as" with flow parser (#13659)
✅ Added test and ported fix in fairly direct way.

9286cdb072 Re-enable disabled flow parser test (#13661)
🚫 Test only.

a5624ea457 v7.15.3
🚫 Test only.

10640b2aad perf: partially replace `.concat` with `.push` (#13609)
🚫 Sucrase doesn't use `.concat`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant