From 651494c2db17d3acb6c8724cba4651a018397bb8 Mon Sep 17 00:00:00 2001 From: Diego Ferreiro Val Date: Mon, 2 Jul 2018 09:52:19 -0700 Subject: [PATCH] fix: add missing npm dependency. Allow dynamic imports (#461) ## Details - Adding `camelcase` npm package - Allowing dynamic imports syntax (follow up with lint rule) ## Does this PR introduce a breaking change? * [x] No --- packages/lwc-compiler/src/babel-plugins.ts | 3 +-- .../transformers/__tests__/transform.spec.ts | 18 ++++++++++++++++++ packages/lwc-template-compiler/package.json | 1 + yarn.lock | 4 ++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/packages/lwc-compiler/src/babel-plugins.ts b/packages/lwc-compiler/src/babel-plugins.ts index bf81232103..739598bc7c 100755 --- a/packages/lwc-compiler/src/babel-plugins.ts +++ b/packages/lwc-compiler/src/babel-plugins.ts @@ -37,11 +37,10 @@ import * as transformPublicFields from '@babel/plugin-proposal-class-properties' import * as transformObjectRestSpread from '@babel/plugin-proposal-object-rest-spread'; // Base babel configuration -// TODO: Need to remove * on the parserOpts plugin - not advised by babel-core export const BABEL_CONFIG_BASE = { babelrc: false, sourceMaps: true, - parserOpts: { plugins: ['*'] }, + parserOpts: { plugins: ['dynamicImport', 'decorators'] }, presets: [], }; diff --git a/packages/lwc-compiler/src/transformers/__tests__/transform.spec.ts b/packages/lwc-compiler/src/transformers/__tests__/transform.spec.ts index 66294ffd7d..6dc5e959ad 100755 --- a/packages/lwc-compiler/src/transformers/__tests__/transform.spec.ts +++ b/packages/lwc-compiler/src/transformers/__tests__/transform.spec.ts @@ -113,6 +113,24 @@ describe('Javascript transform', () => { ); } }); + + it('allows dynamic imports', async () => { + const actual = ` + export function test() { + return import('/test'); + } + `; + + const expected = ` + export function test() { + return import('/test'); + } + `; + + const { code } = await transform(actual, 'foo.js', { namespace: 'x', name: 'foo' }); + expect(pretify(code)).toBe(pretify(expected)); + + }); }); describe('HTML transform', () => { diff --git a/packages/lwc-template-compiler/package.json b/packages/lwc-template-compiler/package.json index fa0a2d73a9..11dff1e3ff 100644 --- a/packages/lwc-template-compiler/package.json +++ b/packages/lwc-template-compiler/package.json @@ -27,6 +27,7 @@ "babel-types": "^6.26.0", "babylon": "^6.17.0", "decamelize": "^1.2.0", + "camelcase": "~5.0.0", "he": "^1.1.1", "parse5-with-errors": "^4.0.1" } diff --git a/yarn.lock b/yarn.lock index 3e0f0418f6..6b81e0e10e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2627,6 +2627,10 @@ camelcase@^4.1.0: version "4.1.0" resolved "http://npm.lwcjs.org/camelcase/-/camelcase-4.1.0/d545635be1e33c542649c69173e5de6acfae34dd.tgz#d545635be1e33c542649c69173e5de6acfae34dd" +camelcase@~5.0.0: + version "5.0.0" + resolved "http://npm.lwcjs.org/camelcase/-/camelcase-5.0.0/03295527d58bd3cd4aa75363f35b2e8d97be2f42.tgz#03295527d58bd3cd4aa75363f35b2e8d97be2f42" + caniuse-api@^1.5.2: version "1.6.1" resolved "http://npm.lwcjs.org/caniuse-api/-/caniuse-api-1.6.1/b534e7c734c4f81ec5fbe8aca2ad24354b962c6c.tgz#b534e7c734c4f81ec5fbe8aca2ad24354b962c6c"