FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Update to cjs-module-lexer@1.2.1 by guybedford · Pull Request #38450 · nodejs/node · GitHub

/ node Public

Update to cjs-module-lexer@1.2.1 - #38450

Closed
guybedford wants to merge 4 commits into
nodejs:masterfrom
guybedford:cjs-module-lexer-update
Closed

Update to cjs-module-lexer@1.2.1#38450
guybedford wants to merge 4 commits into
nodejs:masterfrom
guybedford:cjs-module-lexer-update

Conversation

guybedford commented Apr 28, 2021
edited
Loading

Copy link
Copy Markdown
Contributor

This version of cjs-module-lexer@1.2.1 includes support for non-identifier exports thanks to @nicolo-ribaudo.

This will mean import { "?" as name } from 'cjs' for exports['?'] = 'export' can be supported.

In versions of Node.js without string import support, import * as m from 'cjs'; m['?'] can be used instead for these cases as well.

Test included to verify the behaviour.

Copy link
Copy Markdown
Contributor Author

/cc @nodejs/modules

github-actions Bot added the needs-ci PRs that need a full CI run. label Apr 28, 2021
guybedford requested a review from bmeck April 28, 2021 11:19

aduh95 commented Apr 28, 2021

Copy link
Copy Markdown
Contributor

#37712 (comment)

[cjs-module-lexer]: https://github.com/guybedford/cjs-module-lexer/tree/1.1.1

bmeck commented Apr 28, 2021

Copy link
Copy Markdown
Member

reading v8/v8@81d168d , do we ensure we don't have unpaired surrogates in the lexer? Luckily even w/ the internal name stuff v8 does they didn't use the same space for the exports so it should be safe

Copy link
Copy Markdown
Contributor Author

@bmeck the module load would fail on unpaired surrogates due to the CJS loader failing execution as it wouldn't be valid JS source text. The lexer itself does not bail on unpaired surrogates though (it handles stepping through surrogates but not validating them for performance), so would still return the exports as part of its analysis but this would be unobservable to users.

bmeck commented Apr 28, 2021

Copy link
Copy Markdown
Member

@guybedford

My concern is for valid CJS that exports unpaired surrogates like (this does not play with WASM's requirement of valid UTF8):

// '\u{D83C}\u{DF10}' is 🌐, 2 surrogates
module.exports = {
  '\u{D83C}': 123,
  '\uDF10': 456,
};

Copy link
Copy Markdown
Contributor Author

Ah thanks for clarifying. Yes we will parse and support unpaired surrogates just like normal JS since the lexer runs as UTF-16. Is that a problem?

Copy link
Copy Markdown
Contributor

I can open a PR to cjs-module-lexer to disallow them, but reading tc39/ecma262#2154 I think that the spec wouldn't mandate that imported non-ESM modules must only have valid unicode exports. As far as I understand, it only mandates that you cannot have an import/export with unparied surrogates in an ESM file.

i.e. if we merge this PR without disallowing unparied surrogates, I don't think this would violate the spec:

// dep.cjs
module.exports = {
  '\u{D83C}': 123,
  '\uDF10': 456,
};
import * as dep from "./dep.cjs";

dep["\uDF10"]; // 456, not undefined

bmeck commented Apr 28, 2021

Copy link
Copy Markdown
Member

The spec was written in a way to explicitly ban them and was generally thought that UTF8 compatibility was desired so WASM could properly integrate against any module JS deals with. If WASM directly imported that CJS module I'm unclear what would happen but it certainly wouldn't be able to use those exports. I'd prefer we disable them just to ensure compatibility unless there is reason to allow them.

nicolo-ribaudo commented Apr 28, 2021
edited
Loading

Copy link
Copy Markdown
Contributor

I'll prepare a PR. "disallow" = "ignore it", right? (not throwing)

bmeck commented Apr 28, 2021

Copy link
Copy Markdown
Member

@nicolo-ribaudo yes, just drop them/ignore them. As long as they don't show up in the exported names we should be safe. No reason to error/throw.

guybedford changed the title Update to cjs-module-lexer@1.2.0 Update to cjs-module-lexer@1.2.1 Apr 29, 2021

Copy link
Copy Markdown
Contributor Author

@bmeck I've updated to cjs-module-lexer@1.2.1 here with support for unicode escapes in strings and surrogate validation as discussed.

bmeck left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

let's do this~, LGTM

Copy link
Copy Markdown
Collaborator

bmeck commented Apr 29, 2021

Copy link
Copy Markdown
Member

can we get a rocket emoji reaction for a fast track to this since it is trying to sync up w/ native ESM that is out in 16?

aduh95 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

RSLGTM

Copy link
Copy Markdown
Collaborator

Trott left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Rubber-stamp LGTM

Trott added the fast-track PRs that do not need to wait for 48 hours to land. label Apr 29, 2021

Copy link
Copy Markdown
Collaborator

guybedford commented Apr 30, 2021
edited
Loading

Copy link
Copy Markdown
Contributor Author

Landed in 50991df.

guybedford closed this Apr 30, 2021
guybedford added a commit that referenced this pull request Apr 30, 2021
PR-URL: #38450
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
aduh95 removed the fast-track PRs that do not need to wait for 48 hours to land. label Apr 30, 2021
targos pushed a commit that referenced this pull request May 3, 2021
PR-URL: #38450
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
targos mentioned this pull request May 3, 2021
targos pushed a commit that referenced this pull request May 30, 2021
PR-URL: #38450
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
targos pushed a commit that referenced this pull request Jun 5, 2021
PR-URL: #38450
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
targos pushed a commit that referenced this pull request Jun 5, 2021
PR-URL: #38450
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
targos pushed a commit that referenced this pull request Jun 11, 2021
PR-URL: #38450
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
guybedford added a commit to guybedford/node that referenced this pull request Jul 17, 2021
PR-URL: nodejs#38450
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
richardlau pushed a commit that referenced this pull request Jul 23, 2021
PR-URL: #38450
Backport-PR-URL: #39422
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
richardlau mentioned this pull request Jul 23, 2021
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants


Back | FazBrowse Home | New Git URL