Skip to content

Plugin to transform dynamic import using the spec mode require wrapper#4986

Closed
Jessidhia wants to merge 109 commits intobabel:masterfrom
Jessidhia:commonjs-dynamic-import
Closed

Plugin to transform dynamic import using the spec mode require wrapper#4986
Jessidhia wants to merge 109 commits intobabel:masterfrom
Jessidhia:commonjs-dynamic-import

Conversation

@Jessidhia
Copy link
Copy Markdown
Member

@Jessidhia Jessidhia commented Dec 10, 2016

Q A
Bug fix? no
Breaking change? no
New feature? yes
Deprecations? no
Spec compliancy? yes
Tests added/pass? yes
Fixed tickets
License MIT
Doc PR
Dependency Changes

This transforms dynamic import() calls into Promise-wrapped require calls that go through the commonjs spec: true import helper.

Per the latest TC39 meeting, the resulting Promise always runs on the next tick (always asynchronously).

This continues off another PR so the diff is huge for now 😅

Input

async function x () {
  await import(`some${'module'}`)
}

Output

async function x () {
  await Promise.resolve().then(() => _specRequireInterop(require(`some${'module'}`)));
}

function _specRequireInterop(obj) {
  // return obj if obj.__esModule, wrap in module with single default export otherwise
}

Diogo Franco (Kovensky) added 30 commits December 9, 2016 00:12
* master:
  update `regenerator-runtime` in `babel-polypill` (babel#4966)
  Temp fix for make watch [skip ci] (babel#4967)
  Add (and fix) failing test of function parameter bindings in a catch block (babel#4880)
  Upgrade regenerator-runtime to version 0.10.0. (babel#4877)
  Add `/.test` and `/src` to `babel-plugin-transform-regenerator` `.npmignore`. (babel#4961) [skip ci]
  Only base async fn arity on non-default/non-rest params - fixes babel#4891 (babel#4901)
  Add generator support for Import (babel#4945)
Throws in v8 with "Invalid property descriptor. Cannot both specify
accessors and a value or writable attribute"

I guess this is why the spec defines "magic changing values" instead of
getters 😅
Repeat the shorter identifier in the block.
Mostly for testing interaction of the transform with other es2015
plugins.
If they're named, they can be modified, so the binding has to be kept
live.
Diogo Franco (Kovensky) added 20 commits December 12, 2016 11:19
* master:
  make installing runtime/transform-runtime clearer [skip ci] (babel#4991)
  Add example to es2015-unicode-regex [skip ci] (babel#4983)
  v6.20.3
  Calculate the correct arity for async functions with destructuring - fixes babel#4977 (babel#4978)
  v6.20.2
  fix object spread (babel#4976)
  fix clean lib
  update readme [skip ci]
  v6.20.1
  Fix nested object spread (babel#4974)
  v6.20.0
  v6.20.0 changelog [skip ci] (babel#4971)
  Raise limit on code size before compacting (babel#4965)
  Use regenerator-transform to implement babel-plugin-transform-regenerator (babel#4881)
  Add getBindingIdentifierPaths/getOuterBindingIdentifierPaths (babel#4876)
  Hoist generateDeclaredUidIdentifier helper function (babel#4934)
Even if the path.remove did work, the import would have been deleted
without generating the corresponding require.
* modules-commonjs-spec: (67 commits)
  Remove accidental !
  Be more proactive with the Invalid import throw
  Convert spec-test-helpers to ES6
  Avoid calling scope.getBinding on Flow types
  Remove unused variable, update fixture
  Huge refactoring; reimplement spec / specImport modes with visitors
  Build the babel-runtime dist scripts from current code
  transform-runtime: flag blacklisted helpers for skipping transform
  Allow the helperGenerator hook to return the helper itself
  Fix order in options.json; test still failing
  Add failing test (fix TODO)
  Fix crash when processing ThisExpression
  Update fixtures
  Use a helper for the SameValue check
  Update fixtures
  Use better SameValue algorithm
  Use propertyIsEnumerable instead of getOwnPropertyDescriptor
  Add missing before hooks; fix tests failing on Node < 6
  make installing runtime/transform-runtime clearer [skip ci] (babel#4991)
  Check if renamed reexports are correctly exported
  ...
@nicolo-ribaudo
Copy link
Copy Markdown
Member

@Jessidhia Is this PR still needed? We now support import() in node by delegating to babel-plugin-transform-dynamic-import-node in @babel/plugin-proposal-dynamic-import

@nicolo-ribaudo
Copy link
Copy Markdown
Member

This is supported now in @babel/plugin-proposal-dynamic-import.

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Feb 10, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: New Feature 🚀 A type of pull request used for our changelog categories Spec: Dynamic Import

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants