-
-
Notifications
You must be signed in to change notification settings - Fork 30
feat: introduce API parity between JS and WASM implementation #27
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
Changes from all commits
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 |
|---|---|---|
|
|
@@ -37,7 +37,7 @@ const ExportStar = 2; | |
|
|
||
| const strictReserved = new Set(['implements', 'interface', 'let', 'package', 'private', 'protected', 'public', 'static', 'yield', 'enum']); | ||
|
|
||
| module.exports = function parseCJS (source, name = '@') { | ||
| function parseCJS (source, name = '@') { | ||
| resetState(); | ||
| try { | ||
| parseSource(source); | ||
|
|
@@ -899,7 +899,7 @@ function tryParseLiteralExports () { | |
|
|
||
| // --- Extracted from AcornJS --- | ||
| //(https://github.com/acornjs/acorn/blob/master/acorn/src/identifier.js#L23 | ||
| // | ||
| // | ||
| // MIT License | ||
|
|
||
| // Copyright (C) 2012-2018 by various contributors (see AUTHORS) | ||
|
|
@@ -1034,7 +1034,7 @@ function throwIfImportStatement () { | |
| case 46/*.*/: | ||
| throw new Error('Unexpected import.meta in CJS module.'); | ||
| return; | ||
|
|
||
| default: | ||
| // no space after "import" -> not an import keyword | ||
| if (pos === startPos + 6) | ||
|
|
@@ -1203,7 +1203,7 @@ function readPrecedingKeyword (pos, match) { | |
| } | ||
|
|
||
| function readPrecedingKeyword1 (pos, ch) { | ||
| return source.charCodeAt(pos) === ch && (pos === 0 || isBrOrWsOrPunctuatorNotDot(source.charCodeAt(pos - 1))); | ||
| return source.charCodeAt(pos) === ch && (pos === 0 || isBrOrWsOrPunctuatorNotDot(source.charCodeAt(pos - 1))); | ||
| } | ||
|
|
||
| // Detects one of case, debugger, delete, do, else, in, instanceof, new, | ||
|
|
@@ -1274,7 +1274,7 @@ function isExpressionKeyword (pos) { | |
| // throw | ||
| return readPrecedingKeyword(pos - 2, 'thr'); | ||
| default: | ||
| return false; | ||
| return false; | ||
| } | ||
| } | ||
| return false; | ||
|
|
@@ -1320,3 +1320,8 @@ function isExpressionTerminator (curPos) { | |
| } | ||
| return false; | ||
| } | ||
|
|
||
| const initPromise = Promise.resolve(); | ||
|
|
||
| module.exports.init = () => initPromise; | ||
| module.exports.parse = parseCJS; | ||
|
Comment on lines
+1326
to
+1327
Contributor
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. Note that this could be done without breaking changes: module.exports = (source, name) => parseCJS(source, name);
module.exports.init = () => initPromise;
module.exports.parse = parseCJS;
Member
Author
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. good point. @guybedford thoughts?
Collaborator
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. Let's keep it simple as a major change actually. Saves on type differences / leaving deprecation for subsequent work. |
||
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.
not sure if we should require it to be called or not. E.g. what happens if I use
import('cjs-module-lexer')? Possibly confusing. Dunno 🙂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.
since we're changing the API regardless it might be worth it. happy to make the change if you want 👍
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.
Strictly speaking, the way the exports are defined in https://github.com/guybedford/cjs-module-lexer/blob/master/package.json#L6,
import()should always get the ES module form by definition of the resolution rules and even in bundlers (which RollupJS and Webpack support now!)