Skip to content

Commit

Permalink
[BUGFIX] Make loose mode in class properties transform respect B… (#307)
Browse files Browse the repository at this point in the history
[BUGFIX] Make loose mode in class properties transform respect Babel settings
  • Loading branch information
rwjblue authored Nov 19, 2019
2 parents 738080f + 42997b1 commit b750535
Show file tree
Hide file tree
Showing 5 changed files with 426 additions and 234 deletions.
15 changes: 5 additions & 10 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,22 @@ environment:
- nodejs_version: "8"
- nodejs_version: "10"

cache:
- '%APPDATA%\npm-cache'

# Install scripts. (runs after repo cloning)
install:
- git rev-parse HEAD
# Get the latest stable version of Node 0.STABLE.latest
- ps: Install-Product node $env:nodejs_version
# Typical npm stuff.
- md C:\nc
- npm config set cache C:\nc
- npm version
- npm install phantomjs-prebuilt
- npm install mocha-appveyor-reporter
- npm install --no-optional
- yarn config set cache C:\nc
- yarn add phantomjs-prebuilt --ignore-engines
- yarn add mocha-appveyor-reporter --ignore-engines
- yarn install --ignore-engines

# Post-install test scripts.
test_script:
# Output useful info for debugging.
- npm version
- cmd: npm test
- cmd: yarn test

# Don't actually build.
build: off
Expand Down
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ module.exports = {
let userPostTransformPlugins = addonProvidedConfig.postTransformPlugins;

if (shouldIncludeDecoratorPlugins) {
userPlugins = this._addDecoratorPlugins(userPlugins.slice());
userPlugins = this._addDecoratorPlugins(userPlugins.slice(), addonProvidedConfig.options);
}

options.plugins = [].concat(
Expand Down Expand Up @@ -326,7 +326,7 @@ module.exports = {
return customOptions.disableDecoratorTransforms !== true;
},

_addDecoratorPlugins(plugins) {
_addDecoratorPlugins(plugins, options) {
const { hasPlugin, addPlugin } = require('ember-cli-babel-plugin-helpers');

if (hasPlugin(plugins, '@babel/plugin-proposal-decorators')) {
Expand Down Expand Up @@ -355,7 +355,7 @@ module.exports = {
} else {
addPlugin(
plugins,
[require.resolve('@babel/plugin-proposal-class-properties'), { loose: true }],
[require.resolve('@babel/plugin-proposal-class-properties'), { loose: options.loose || false }],
{
after: ['@babel/plugin-proposal-decorators'],
before: ['@babel/plugin-transform-typescript']
Expand Down
38 changes: 28 additions & 10 deletions node-tests/addon-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ describe('ember-cli-babel', function() {
});
}));

it("does not remove _asyncToGenerator helper function when used together with debug-macros", co.wrap(function* () {
it("does not remove regeneratorRuntime.async helper function when used together with debug-macros", co.wrap(function* () {
input.write({
"foo.js": stripIndent`
import { assert } from '@ember/debug';
Expand All @@ -167,7 +167,7 @@ describe('ember-cli-babel', function() {

let contents = output.read()['foo.js'];

expect(contents).to.include('function _asyncToGenerator');
expect(contents).to.include('regeneratorRuntime.async');
}));

it("allows @ember/debug to be consumed via both debug-macros and ember-modules-api-polyfill", co.wrap(function* () {
Expand All @@ -186,7 +186,7 @@ describe('ember-cli-babel', function() {
let contents = output.read()['foo.js'];

expect(contents).to.not.include('@ember/debug');
expect(contents).to.include('function _asyncToGenerator');
expect(contents).to.include('regeneratorRuntime.async');
expect(contents).to.include('Ember.inspect;');
expect(contents).to.not.include('assert');
}));
Expand Down Expand Up @@ -748,7 +748,7 @@ describe('ember-cli-babel', function() {

describe('_addDecoratorPlugins', function() {
it('should include babel transforms by default', function() {
expect(this.addon._addDecoratorPlugins([]).length).to.equal(2, 'plugins added correctly');
expect(this.addon._addDecoratorPlugins([], {}).length).to.equal(2, 'plugins added correctly');
});

it('should include only fields if it detects decorators plugin', function() {
Expand All @@ -758,9 +758,12 @@ describe('ember-cli-babel', function() {
}
};

expect(this.addon._addDecoratorPlugins([
['@babel/plugin-proposal-decorators']
]).length).to.equal(2, 'plugins were not added');
expect(
this.addon._addDecoratorPlugins([
['@babel/plugin-proposal-decorators']
],
{}
).length).to.equal(2, 'plugins were not added');
});

it('should include only decorators if it detects class fields plugin', function() {
Expand All @@ -770,9 +773,24 @@ describe('ember-cli-babel', function() {
}
};

expect(this.addon._addDecoratorPlugins([
['@babel/plugin-proposal-class-properties']
]).length).to.equal(2, 'plugins were not added');
expect(
this.addon._addDecoratorPlugins(
[
['@babel/plugin-proposal-class-properties']
],
{}
).length
).to.equal(2, 'plugins were not added');
});

it('should use babel options loose mode for class properties', function() {
let strictPlugins = this.addon._addDecoratorPlugins([], {});

expect(strictPlugins[1][1].loose).to.equal(false, 'loose is false if no option is provided');

let loosePlugins = this.addon._addDecoratorPlugins([], { loose: true });

expect(loosePlugins[1][1].loose).to.equal(true, 'loose setting added correctly');
});
});

Expand Down
19 changes: 11 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@
"test:node:debug": "mocha debug node-tests"
},
"dependencies": {
"@babel/core": "^7.0.0",
"@babel/plugin-proposal-class-properties": "^7.3.4",
"@babel/plugin-proposal-decorators": "^7.3.0",
"@babel/plugin-transform-modules-amd": "^7.0.0",
"@babel/plugin-transform-runtime": "^7.2.0",
"@babel/polyfill": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/runtime": "^7.2.0",
"@babel/core": "^7.7.0",
"@babel/plugin-proposal-class-properties": "^7.7.0",
"@babel/plugin-proposal-decorators": "^7.7.0",
"@babel/plugin-transform-modules-amd": "^7.5.0",
"@babel/plugin-transform-runtime": "^7.6.0",
"@babel/polyfill": "^7.7.0",
"@babel/preset-env": "^7.7.0",
"@babel/runtime": "^7.7.0",
"amd-name-resolver": "^1.2.1",
"babel-plugin-debug-macros": "^0.3.0",
"babel-plugin-ember-modules-api-polyfill": "^2.12.0",
Expand Down Expand Up @@ -94,6 +94,9 @@
"engines": {
"node": "6.* || 8.* || >= 10.*"
},
"resolutions": {
"**/engine.io": "~3.3.0"
},
"publishConfig": {
"registry": "https://registry.npmjs.org"
},
Expand Down
Loading

0 comments on commit b750535

Please sign in to comment.