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
Improve module expression parsing/printing #14980
Changes from 6 commits
5dba903
101cad5
f31ab0f
5215c61
5c60588
0dc2ccc
1ec194d
199f8e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module /* 1 */ { /* 2 */ } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"plugins": ["moduleBlocks"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module /* 1 */ { | ||
/* 2 */ | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,5 +11,5 @@ | |
"sourcesContent": [ | ||
"const m = module { export const foo = \"foo\" };\nmodule {\n foo;\n bar;\n};\nfoo(module {});" | ||
], | ||
"mappings": "AAAA,MAAMA,CAAC,GAAG;EAAS,OAAO,MAAMC,GAAG,GAAG,KAAK;AAAC,CAAC;AAC7C;EACEA,GAAG;EACHC,GAAG;AACL,CAAC;AACDD,GAAG,CAAC,SAAS,CAAC" | ||
"mappings": "AAAA,MAAMA,CAAC,GAAG;EAAS,OAAO,MAAMC,GAAG,GAAG,KAAK;AAAC,CAAC;AAC7C;EACEA,GAAG;EACHC,GAAG;AACL,CAAC;AACDD,GAAG,CAAC,QAAQ,CAAC,CAAC" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The source map is updated because we now generate two sections There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we could optimize this in the future (directly or in one of @jridgewell's packages) by merging source map segments that are adjacent both in the input and in the output. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shouldn't be technically difficult, but I'm not sure that's better. In the last PR I marked the sourcemap for every ";". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This has to be done in Babel, because the sourcemap packages will not know whether this marking is important or not. Eg, |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module { | ||
"hide source"; | ||
secret; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"plugins": ["moduleBlocks"], | ||
"sourceType": "module" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module { | ||
"hide source"; | ||
|
||
secret; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -222,6 +222,7 @@ export default abstract class StatementParser extends ExpressionParser { | |
this.raise(Errors.ModuleExportUndefined, { at, localName }); | ||
} | ||
} | ||
this.eat(tt.eof); // stop before } when parsing a module expression | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need to eat it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we move it as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we eat |
||
return this.finishNode(program, "Program"); | ||
} | ||
|
||
|
@@ -1123,6 +1124,7 @@ export default abstract class StatementParser extends ExpressionParser { | |
tt.braceR, | ||
afterBlockParse, | ||
); | ||
this.next(); // eat tt.braceR | ||
if (createNewLexicalScope) { | ||
this.scope.exit(); | ||
} | ||
|
@@ -1204,8 +1206,6 @@ export default abstract class StatementParser extends ExpressionParser { | |
if (!oldStrict) { | ||
this.setStrict(false); | ||
} | ||
|
||
this.next(); | ||
} | ||
|
||
// Parse a regular `for` loop. The disambiguation code in | ||
|
@@ -1881,6 +1881,7 @@ export default abstract class StatementParser extends ExpressionParser { | |
this.prodParam.enter(PARAM); | ||
const body: N.Node[] = (member.body = []); | ||
this.parseBlockOrModuleBlockBody(body, undefined, false, tt.braceR); | ||
this.next(); // eat tt.braceR | ||
this.prodParam.exit(); | ||
this.scope.exit(); | ||
this.state.labels = oldLabels; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module{|foo:42|}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before this PR we parses this input as if it were // note the extra required `{` after `module`
module {
{| foo: 42 |}
} This is now fixed by expecting |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"plugins": [ | ||
"moduleBlocks", | ||
[ | ||
"recordAndTuple", | ||
{ | ||
"syntaxType": "bar" | ||
} | ||
] | ||
], | ||
"throws": "Unexpected token, expected \"{\" (1:6)" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that currently our generator is not allowed to throw exceptions, I personally prefer not to have this try.