Skip to content
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

String import/export specifier #12091

Merged
merged 25 commits into from Oct 14, 2020
Merged

Conversation

@JLHwung
Copy link
Contributor

@JLHwung JLHwung commented Sep 22, 2020

Q                       A
Fixed Issues? Implements tc39/ecma262#2154
Minor: New Feature? Yes
Tests Added + Pass? Yes
Documentation PR Link babel/website#2396
Any Dependency Changes? @babel/helper-module-transforms now depends on @babel/helper-validator-identifier
License MIT

This PR implements support of Arbitrary module namespace identifier names behind moduleStringNames parser plugin

import { "some imports" as foo } from "module"
export { foo as "some exports" } from "module"
export { "another imports" as "another exports" } from "module"
export { "rest exports" } from "module"

Babel can now parse such code and transform it to CommonJS/AMD/UMD/SystemJS code. Take CommonJS as an output example

const m = require("module");
foo = m["some imports"];
exports["some exports"] = m.foo;
exports["another exports"] = m["another imports"];
exports["rest exports"] = m["rest exports"];

A new package @babel/plugin-syntax-module-string-names is introduced. See also https://github.com/babel/babel/pull/12091/files#diff-ef433cb06c064c1e7a5af0f448d98a78 for AST spec changes.

Todo:

  • umd-transform
  • amd-transform
  • systemjs-transform (/cc @guybedford)

@babel-bot
Copy link
Collaborator

@babel-bot babel-bot commented Sep 22, 2020

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/29849/

@codesandbox
Copy link

@codesandbox codesandbox bot commented Sep 22, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 107444b:

Sandbox Source
babel-repl-custom-plugin Configuration
babel-plugin-multi-config Configuration
@JLHwung JLHwung added this to the v7.12.0 milestone Sep 22, 2020
@JLHwung JLHwung force-pushed the JLHwung:string-module-specifier-name branch from bd69ecd to 425637a Sep 22, 2020
@JLHwung JLHwung marked this pull request as ready for review Sep 22, 2020
@JLHwung JLHwung force-pushed the JLHwung:string-module-specifier-name branch 2 times, most recently from d7f2778 to c50c767 Sep 25, 2020
Copy link
Contributor

@guybedford guybedford left a comment

SystemJS output looks great, and glad it fixed some bugs too.

Copy link
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

I think that we should introduce this behind a syntax plugin. Even if the spec PR has consensus, it will still take a while to be merged because it doesn't have tests.

Also, for example tc39/ecma262#1174 still took a few months after having consensus and tests.

@JLHwung JLHwung force-pushed the JLHwung:string-module-specifier-name branch from c50c767 to c63fd3c Sep 28, 2020
@JLHwung JLHwung changed the title String module specifier name String import/export specifier Sep 28, 2020
@JLHwung JLHwung force-pushed the JLHwung:string-module-specifier-name branch 4 times, most recently from 7ba178b to 6f141a2 Sep 29, 2020
@JLHwung JLHwung requested a review from nicolo-ribaudo Sep 30, 2020
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

Except for a question (maybe small error) this looks good 👍

exported: Identifier;
local?: Identifier;
exported: Identifier | StringLiteral;
local?: Identifier | StringLiteral;

This comment has been minimized.

@nicolo-ribaudo

nicolo-ribaudo Oct 9, 2020
Member

When can local be a string?

This comment has been minimized.

@JLHwung

JLHwung Oct 9, 2020
Author Contributor

export { "😄" as "😂" } from "emojis"
@JLHwung JLHwung force-pushed the JLHwung:string-module-specifier-name branch from f71402b to 6e0d7bf Oct 9, 2020
@JLHwung JLHwung force-pushed the JLHwung:string-module-specifier-name branch from 6e0d7bf to 0b4dc58 Oct 12, 2020
Copy link
Member

@existentialism existentialism left a comment

Looks great! Just some 🚲shedding on error messages.

JLHwung and others added 4 commits Oct 12, 2020
Co-authored-by: Brian Ng <bng412@gmail.com>
Co-authored-by: Brian Ng <bng412@gmail.com>
@nicolo-ribaudo nicolo-ribaudo merged commit cb30c1d into babel:main Oct 14, 2020
15 of 16 checks passed
15 of 16 checks passed
Prepare Cache
Details
Test on Node.js Latest
Details
Build Babel Artifacts
Details
Test on Node.js (13)
Details
Test on Node.js (12)
Details
Test on Node.js (10)
Details
Test on Node.js (8)
Details
Test on Node.js (6)
Details
test262-pr Workflow: test262-pr
Details
Gitpod Open an online workspace in Gitpod
Details
Travis CI - Pull Request Build Passed
Details
babel/repl REPL preview is available
Details
build-standalone Workflow: build-standalone
Details
ci/codesandbox Building packages succeeded.
Details
codecov/project 91.76% (target 90.00%)
Details
e2e Workflow: e2e
Details
@nicolo-ribaudo nicolo-ribaudo deleted the JLHwung:string-module-specifier-name branch Oct 14, 2020
nicolo-ribaudo added a commit that referenced this pull request Oct 14, 2020
* feat: parse moduleExportName
* feat: add validators
* Support string specifier name in commonjs transform
* Support string specifier name in export-ns-from
* test: add loose testcases
* test: add testcases for amd and umd
* feat: support systemjs
* test: update fixtures fixed in #12110
* add plugin name typings
* test: rename test layout
* feat: implement under moduleStringNames flag
* chore: add plugin syntax module string names
* feat: support ModuleExportName as ModuleExportName
* test: update test fixtures
* fix flow errors
* docs: update AST spec
* feat: support { "some imports" as "some exports" }
* feat: support { "some imports" as "some exports" } in systemjs
* test: add test on `import { "foo" }`
* Address review comments
* add moduleStringNames to missing plugin helpers
* Apply suggestions from code review
* update test fixtures
* Update packages/babel-parser/src/parser/error-message.js
* update test fixtures

Co-Authored-By: Kai Cataldo <kai@kaicataldo.com>
Co-authored-by: Brian Ng <bng412@gmail.com>
@fisker fisker mentioned this pull request Oct 15, 2020
3 of 3 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

6 participants
You can’t perform that action at this time.