Repository navigation
Commit f88678d
committed
[JSC] Import and export declarations should not redeclare a var in module code
https://bugs.webkit.org/show_bug.cgi?id=327927
Reviewed by Yusuke Suzuki.
It is a Syntax Error if a LexicallyDeclaredName of a module also occurs in its
VarDeclaredNames [1], but JSC accepted the following when the var came first.
var x; import { y as x } from "./m.js";
var x; export let x;
var x; export class x { }
Debug builds then hit ASSERT(symbolTableEntry.isNull()) in
BytecodeGenerator::instantiateLexicalVariables.
Parser::declareVariable compares a lexical name with vars only when
m_statementDepth is 1, and import and export declarations were parsed at depth 0.
This patch parses them at depth 1, the depth of top-level statements, by
incrementing it in parseImportDeclaration and parseExportDeclaration as
parseStatementListItem does. Setting the depth to 1 only for exported function
declarations is no longer needed.
[1]: https://tc39.es/ecma262/#sec-module-semantics-static-semantics-early-errors
Tests: JSTests/stress/bigint-to-string-divide-and-conquer-large.js
JSTests/stress/modules-syntax-error-import-and-export-declarations-after-var.js
* JSTests/stress/bigint-to-string-divide-and-conquer-large.js: Added.
(shouldBe):
* JSTests/stress/modules-syntax-error-import-and-export-declarations-after-var.js: Added.
(shouldThrowModuleSyntaxError):
(export.x):
(export.async x):
(export.default.x):
(export.default.async x):
(const.declaration.of.declarations.const.statement.of.f):
(export.default):
(export.C):
(export.let.y):
* JSTests/stress/modules-syntax-error-with-names.js:
* Source/JavaScriptCore/parser/Parser.cpp:
(JSC::Parser<LexerType>::parseImportDeclaration):
(JSC::Parser<LexerType>::parseExportDeclaration):
Canonical link: https://commits.webkit.org/324223@main1 parent 5d5248a commit f88678d
4 files changed
Lines changed: 96 additions & 22 deletions
File tree
- JSTests/stress
- Source/JavaScriptCore/parser
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
228 | 228 | | |
229 | 229 | | |
230 | 230 | | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | 231 | | |
236 | 232 | | |
237 | 233 | | |
238 | 234 | | |
239 | 235 | | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
244 | 240 | | |
245 | 241 | | |
246 | 242 | | |
247 | 243 | | |
248 | 244 | | |
249 | 245 | | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
254 | 250 | | |
255 | 251 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3764 | 3764 | | |
3765 | 3765 | | |
3766 | 3766 | | |
| 3767 | + | |
| 3768 | + | |
3767 | 3769 | | |
3768 | 3770 | | |
3769 | 3771 | | |
| |||
3902 | 3904 | | |
3903 | 3905 | | |
3904 | 3906 | | |
| 3907 | + | |
| 3908 | + | |
3905 | 3909 | | |
3906 | 3910 | | |
3907 | 3911 | | |
| |||
3997 | 4001 | | |
3998 | 4002 | | |
3999 | 4003 | | |
4000 | | - | |
4001 | | - | |
4002 | 4004 | | |
4003 | 4005 | | |
4004 | 4006 | | |
4005 | 4007 | | |
4006 | 4008 | | |
4007 | 4009 | | |
4008 | 4010 | | |
4009 | | - | |
4010 | | - | |
4011 | 4011 | | |
4012 | 4012 | | |
4013 | 4013 | | |
| |||
4123 | 4123 | | |
4124 | 4124 | | |
4125 | 4125 | | |
4126 | | - | |
4127 | | - | |
4128 | | - | |
| 4126 | + | |
4129 | 4127 | | |
4130 | 4128 | | |
4131 | | - | |
4132 | 4129 | | |
4133 | 4130 | | |
4134 | 4131 | | |
| |||
4139 | 4136 | | |
4140 | 4137 | | |
4141 | 4138 | | |
4142 | | - | |
4143 | | - | |
4144 | 4139 | | |
4145 | 4140 | | |
4146 | 4141 | | |
| |||
0 commit comments