Parent: #899
Problem
Nine module-only parser exits still discard JavaScriptCore's diagnostic reason. A WebKit module-parser oracle (JavaScriptCore 625.1.22) confirms these families:
| source | JavaScriptCore |
|---|---|
var x; let x; | Cannot declare a let variable twice: 'x'. |
let x; var x; | Cannot declare a var variable that shadows a let/const/class variable: 'x'. |
import x from "a"; import x from "b"; | Cannot declare an imported binding name twice: 'x'. |
let x; export {x}; export {x}; | Cannot export a duplicate name 'x'. |
export default 1; export default 2; | Only one 'default' export is allowed. |
export {x}; | Exported binding 'x' needs to refer to a top-level declared variable. |
import "m" with {type:"json",type:"json"}; | Unexpected identifier 'type'. A duplicate key for import attributes 'type'. |
import "m" with {type: json}; | Unexpected identifier 'json'. Expected an attribute value. |
export {"x"}; | Cannot use module export names if they reference variable names in the current module. |
export {1}; | Unexpected number '1'. Expected a variable name or a module export name string for the export declaration. |
export {"\uD800" as x} from "m"; | Unexpected string literal "\uD800". Expected a well-formed-unicode string for the module export name. |
<!-- comment | Unexpected token '<' |
zig-js rejects the programs but currently surfaces UnexpectedToken for each. Import-name and exported-name positions use distinct JSC suffixes and must remain distinct.
Implementation shape
- carry declaration-kind reasons through the existing module declaration inventory; use the current pattern shape only on collisions;
- retain duplicate-export and unresolved-local names from the existing export inventory;
- give
ModuleExportNamean explicit grammar context (imported, local export, exported name, import-attribute key); - retain the second import-attribute key/value token;
- attach the already-recorded HTML-comment offset to the offending
<or>token; - add no new accepted-program traversal or allocation.
Verification
- exact WebKit/JSC module differential across declaration order, destructuring, imports, exports, attributes, malformed names, and HTML comments;
- parser module diagnostic tests;
- standalone parser module;
- exact-parent test262 module comparison.