-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
module: CJS exports detection for modules with __esModule export #33416
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
12f935e
module: __esModule CJS exports detection
guybedford fe7c8f0
reembed wasm pending js rewrite
guybedford eaf69c0
recursively parse for __esModule
guybedford 45b53f3
transitive __esModule detection
guybedford 16edbe0
fixup forEach
guybedford File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| MIT License | ||
| ----------- | ||
|
|
||
| Copyright (C) 2018-2020 Guy Bedford | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| { | ||
| 'targets': [ | ||
| { | ||
| 'target_name': 'cjs-module-lexer', | ||
| 'type': 'static_library', | ||
| 'cflags': ['-Wno-implicit-fallthrough', '-Wno-parentheses'], | ||
| 'include_dirs': ['include'], | ||
| 'sources': [ | ||
| 'src/lexer.c', | ||
| ], | ||
| 'direct_dependent_settings': { | ||
| 'include_dirs': ['include'] | ||
| }, | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| #ifndef __CJS_MODULE_LEXER_H__ | ||
| #define __CJS_MODULE_LEXER_H__ | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| #include <stdint.h> | ||
| #include <stdbool.h> | ||
| #include <stddef.h> | ||
| #include <stdio.h> | ||
| #include <string.h> | ||
|
|
||
| struct Slice { | ||
| const uint16_t* start; | ||
| const uint16_t* end; | ||
| }; | ||
| typedef struct Slice Slice; | ||
|
|
||
| struct StarExportBinding { | ||
| const uint16_t* specifier_start; | ||
| const uint16_t* specifier_end; | ||
| const uint16_t* id_start; | ||
| const uint16_t* id_end; | ||
| }; | ||
| typedef struct StarExportBinding StarExportBinding; | ||
|
|
||
| void bail (uint32_t err); | ||
|
|
||
| bool parseCJS (uint16_t* source, uint32_t sourceLen, void (*addExport)(const uint16_t*, const uint16_t*), void (*addReexport)(const uint16_t*, const uint16_t*)); | ||
guybedford marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| void tryBacktrackAddStarExportBinding (uint16_t* pos); | ||
| bool tryParseRequire (bool directStarExport); | ||
guybedford marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| void tryParseLiteralExports (); | ||
| bool readExportsOrModuleDotExports (uint16_t ch); | ||
| void tryParseModuleExportsDotAssign (); | ||
| void tryParseExportsDotAssign (bool assign); | ||
| void tryParseObjectDefineOrKeys (); | ||
| bool identifier (uint16_t ch); | ||
|
|
||
| void throwIfImportStatement (); | ||
| void throwIfExportStatement (); | ||
|
|
||
| void readImportString (const uint16_t* ss, uint16_t ch); | ||
| uint16_t readExportAs (uint16_t* startPos, uint16_t* endPos); | ||
|
|
||
| uint16_t commentWhitespace (); | ||
| void singleQuoteString (); | ||
| void doubleQuoteString (); | ||
| void regularExpression (); | ||
| void templateString (); | ||
| void blockComment (); | ||
| void lineComment (); | ||
|
|
||
| uint16_t readToWsOrPunctuator (uint16_t ch); | ||
|
|
||
| uint32_t fullCharCodeAtLast (uint16_t* pos); | ||
| bool isIdentifierStart (uint32_t code); | ||
| bool isIdentifierChar (uint32_t code); | ||
| int charCodeByteLen (uint32_t ch); | ||
|
|
||
| bool isBr (uint16_t c); | ||
| bool isBrOrWs (uint16_t c); | ||
| bool isBrOrWsOrPunctuator (uint16_t c); | ||
| bool isBrOrWsOrPunctuatorNotDot (uint16_t c); | ||
|
|
||
| bool str_eq2 (uint16_t* pos, uint16_t c1, uint16_t c2); | ||
| bool str_eq3 (uint16_t* pos, uint16_t c1, uint16_t c2, uint16_t c3); | ||
| bool str_eq4 (uint16_t* pos, uint16_t c1, uint16_t c2, uint16_t c3, uint16_t c4); | ||
| bool str_eq5 (uint16_t* pos, uint16_t c1, uint16_t c2, uint16_t c3, uint16_t c4, uint16_t c5); | ||
| bool str_eq6 (uint16_t* pos, uint16_t c1, uint16_t c2, uint16_t c3, uint16_t c4, uint16_t c5, uint16_t c6); | ||
| bool str_eq7 (uint16_t* pos, uint16_t c1, uint16_t c2, uint16_t c3, uint16_t c4, uint16_t c5, uint16_t c6, uint16_t c7); | ||
| bool str_eq9 (uint16_t* pos, uint16_t c1, uint16_t c2, uint16_t c3, uint16_t c4, uint16_t c5, uint16_t c6, uint16_t c7, uint16_t c8, uint16_t c9); | ||
| bool str_eq10 (uint16_t* pos, uint16_t c1, uint16_t c2, uint16_t c3, uint16_t c4, uint16_t c5, uint16_t c6, uint16_t c7, uint16_t c8, uint16_t c9, uint16_t c10); | ||
| bool str_eq13 (uint16_t* pos, uint16_t c1, uint16_t c2, uint16_t c3, uint16_t c4, uint16_t c5, uint16_t c6, uint16_t c7, uint16_t c8, uint16_t c9, uint16_t c10, uint16_t c11, uint16_t c12, uint16_t c13); | ||
| bool str_eq18 (uint16_t* pos, uint16_t c1, uint16_t c2, uint16_t c3, uint16_t c4, uint16_t c5, uint16_t c6, uint16_t c7, uint16_t c8, uint16_t c9, uint16_t c10, uint16_t c11, uint16_t c12, uint16_t c13, uint16_t c14, uint16_t c15, uint16_t c16, uint16_t c17, uint16_t c18); | ||
|
|
||
| bool readPrecedingKeyword2(uint16_t* pos, uint16_t c1, uint16_t c2); | ||
| bool readPrecedingKeyword3(uint16_t* pos, uint16_t c1, uint16_t c2, uint16_t c3); | ||
| bool readPrecedingKeyword4(uint16_t* pos, uint16_t c1, uint16_t c2, uint16_t c3, uint16_t c4); | ||
| bool readPrecedingKeyword5(uint16_t* pos, uint16_t c1, uint16_t c2, uint16_t c3, uint16_t c4, uint16_t c5); | ||
| bool readPrecedingKeyword6(uint16_t* pos, uint16_t c1, uint16_t c2, uint16_t c3, uint16_t c4, uint16_t c5, uint16_t c6); | ||
| bool readPrecedingKeyword7(uint16_t* pos, uint16_t c1, uint16_t c2, uint16_t c3, uint16_t c4, uint16_t c5, uint16_t c6, uint16_t c7); | ||
|
|
||
| bool keywordStart (uint16_t* pos); | ||
| bool isExpressionKeyword (uint16_t* pos); | ||
| bool isParenKeyword (uint16_t* pos); | ||
| bool isPunctuator (uint16_t charCode); | ||
| bool isExpressionPunctuator (uint16_t charCode); | ||
| bool isExpressionTerminator (uint16_t* pos); | ||
|
|
||
| void nextChar (uint16_t ch); | ||
| void nextCharSurrogate (uint16_t ch); | ||
| uint16_t readChar (); | ||
|
|
||
| void syntaxError (); | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
| #endif /* __CJS_MODULE_LEXER_H__ */ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| { | ||
| "name": "cjs-module-lexer", | ||
| "version": "0.2.12", | ||
| "description": "Lexes CommonJS modules, returning their named exports metadata", | ||
| "main": "dist/lexer.js", | ||
| "module": "dist/lexer.mjs", | ||
| "scripts": { | ||
| "test": "NODE_OPTIONS=\"--experimental-modules\" mocha -b -u tdd test/*.cjs", | ||
| "build": "node --experimental-modules build.js && babel dist/lexer.mjs | terser -o dist/lexer.js", | ||
| "build-wasm": "make lib/lexer.wasm && node build.js", | ||
| "bench": "node --experimental-modules --expose-gc bench/index.js", | ||
| "prepublishOnly": "make optimize && npm run build", | ||
| "footprint": "make optimize && npm run build && cat dist/lexer.js | gzip -9f | wc -c" | ||
| }, | ||
| "author": "Guy Bedford", | ||
| "license": "MIT", | ||
| "devDependencies": { | ||
| "@babel/cli": "^7.5.5", | ||
| "@babel/core": "^7.5.5", | ||
| "@babel/plugin-transform-modules-commonjs": "^7.5.0", | ||
| "kleur": "^2.0.2", | ||
| "mocha": "^5.2.0", | ||
| "terser": "^4.1.4" | ||
| }, | ||
| "files": [ | ||
| "dist" | ||
| ], | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/guybedford/cjs-module-lexer.git" | ||
| }, | ||
| "bugs": { | ||
| "url": "https://github.com/guybedford/cjs-module-lexer/issues" | ||
| }, | ||
| "homepage": "https://github.com/guybedford/cjs-module-lexer#readme" | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.