BUG: Module exporting undeclared name should be a syntax error
See original GitHub issueAnother bug I found whilst working on #5759 though I do not currently have a fix planned for this.
Per https://tc39.github.io/ecma262/#sec-module-semantics-static-semantics-early-errors It is a Syntax Error if any element of the ExportedBindings of ModuleItemList does not also occur in either the VarDeclaredNames of ModuleItemList, or the LexicallyDeclaredNames of ModuleItemList.
POC:
//start.js
import {Fun} from "./other.js";
print(Fun);
//other.js
export {anything as Fun};
Note the same repros if instead of “anything” you use any other undeclared name OR use a global like Number or Array or if you don’t alias “anything”.
Output with ch: undefined
, jsc and v8 throw Syntax Errors
(Can’t do an eshost repro at the moment as eshost doesn’t yet interact with ch’s module flag)
This causes numerous test262 failures.
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Module exporting undeclared name should be a syntax error ...
I've been thinking about how to fix this - it seems it needs to involve adding a step at the end of parsing...
Read more >Go linter in VS code not working for packages across multiple ...
package foobar func SayHello() string { return "Hello, world!" } then in foo.go I get a linter error that SayHello is an undeclared...
Read more >ReferenceError: assignment to undeclared variable "x"
The JavaScript strict mode-only exception "Assignment to undeclared variable" occurs when the value has been assigned to an undeclared variable.
Read more >Changelog — Python 3.11.1 documentation
gh-96005: On WASI ENOTCAPABLE is now mapped to PermissionError . The errno modules exposes the new error number. getpath.py now ignores PermissionError when...
Read more >Google TypeScript Style Guide
For non-exported symbols, sometimes the name and type of the function or parameter is enough. Code will usually benefit from more documentation than...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Seems like something we should be able to do at name binding. We do push a pidref to ‘anything’ when we export it, right? When we bind names, we could throw a SyntaxError if we find a referenced name with no declaration.
You’re right, no pid ref is pushed in this case. It looks like we implemented it without attempting to bind the exported name to a declaration. Either we missed this requirement in the spec or implemented an earlier spec that didn’t contain the requirement.
What you’ll want to do is call PushPidRef from Parser::AddModuleImportOrExportEntry, passing in the IdentPtr of the local name, and store the resulting PidRefStack* on the export record. Binding will fill in the Symbol* on the PidRefStack. When we later resolve the export entries, a null Symbol* will indicate an undeclared name. Note that this has to be done whether buildAST is false or true, so the caller of AddModuleImportOrExportEntry will have to make the call in both cases.
Does all that make sense?