Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-ember-modules-api-polyfill

Package Overview
Dependencies
Maintainers
4
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-ember-modules-api-polyfill - npm Package Compare versions

Comparing version 2.2.1 to 2.3.0

2

package.json
{
"name": "babel-plugin-ember-modules-api-polyfill",
"version": "2.2.1",
"version": "2.3.0",
"description": "Polyfill for Ember JS API.",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -18,3 +18,2 @@ 'use strict';

const t = babel.types;
// Flips the ember-rfc176-data mapping into an 'import' indexed object, that exposes the

@@ -24,3 +23,3 @@ // default import as well as named imports, e.g. import {foo} from 'bar'

mapping.forEach(exportDefinition => {
const imported = exportDefinition.global.substr('Ember.'.length);
const imported = exportDefinition.global;
const importRoot = exportDefinition.module;

@@ -60,11 +59,6 @@ let importName = exportDefinition.export;

if (local.name !== 'Ember') {
// Repalce the node with a new `var name = Ember`
replacements.push(
t.variableDeclaration('var', [
t.variableDeclarator(
local,
t.identifier('Ember')
),
])
);
replacements.push([
local.name,
'Ember',
]);
}

@@ -121,19 +115,22 @@ removals.push(specifierPath);

// Repalce the node with a new `var name = Ember.something`
replacements.push(
t.variableDeclaration('var', [
t.variableDeclarator(
local,
t.memberExpression(t.identifier('Ember'), t.identifier(global))
),
])
);
// Replace the occurences of the imported name with the global name.
replacements.push([
local.name,
global,
]);
});
}
if (removals.length > 0 && removals.length === node.specifiers.length) {
path.replaceWithMultiple(replacements);
} else if (replacements.length > 0) {
removals.forEach(specifierPath => specifierPath.remove());
path.insertAfter(replacements);
if (removals.length > 0) {
replacements.forEach(replacement => {
let local = replacement[0];
let global = replacement[1];
path.scope.rename(local, global);
});
if (removals.length === node.specifiers.length) {
path.remove();
} else {
removals.forEach(specifierPath => specifierPath.remove());
}
}

@@ -195,6 +192,6 @@ },

let declaration;
const memberExpression = t.memberExpression(t.identifier('Ember'), t.identifier(global));
const globalAsIdentifier = t.identifier(global);
if (exported.name === 'default') {
declaration = t.exportDefaultDeclaration(
memberExpression
globalAsIdentifier
);

@@ -207,3 +204,3 @@ } else {

exported,
memberExpression
globalAsIdentifier
),

@@ -210,0 +207,0 @@ ]),

@@ -42,4 +42,4 @@ 'use strict';

matches(
`import ${localName} from '${importRoot}';`,
`var ${varName} = ${exportDefinition.global};`
`import ${localName} from '${importRoot}';var _x = ${varName}`,
`var _x = ${exportDefinition.global};`
);

@@ -49,8 +49,27 @@ });

// Ensure it works in complex scopes
describe(`ember-modules-api-polyfill-import-complex-scopes`, () => {
matches(
`import { isEmpty } from '@ember/utils';
var _x = someArray.every(item => isEmpty(item));
var _y = someOtherArray.some((isEmpty, idx) => isEmpty(idx));`,
`
var _x = someArray.every(item => Ember.isEmpty(item));
var _y = someOtherArray.some((isEmpty, idx) => isEmpty(idx));`
);
});
// Ensure mapping without reference just removes the line
describe(`ember-modules-api-polyfill-import-without-reference`, () => {
matches(
`import { empty } from '@ember/object/computed';`,
``
);
});
// Ensure mapping multiple imports makes multiple variables
describe(`ember-modules-api-polyfill-import-multiple`, () => {
matches(
`import { empty, notEmpty } from '@ember/object/computed';`,
`var empty = Ember.computed.empty;
var notEmpty = Ember.computed.notEmpty;`
`import { empty, notEmpty } from '@ember/object/computed';var _x = empty;var _y = notEmpty;`,
`var _x = Ember.computed.empty;var _y = Ember.computed.notEmpty;`
);

@@ -62,4 +81,4 @@ });

matches(
`import jQuery from 'jquery'; import RSVP from 'rsvp';`,
`var jQuery = Ember.$;\nvar RSVP = Ember.RSVP;`
`import jQuery from 'jquery'; import RSVP from 'rsvp';var $ = jQuery;var _y = RSVP`,
`var $ = Ember.$;var _y = Ember.RSVP;`
);

@@ -71,4 +90,4 @@ });

matches(
`import { empty as isEmpty } from '@ember/object/computed';`,
`var isEmpty = Ember.computed.empty;`
`import { empty as isEmpty } from '@ember/object/computed';var _x = isEmpty;`,
`var _x = Ember.computed.empty;`
);

@@ -80,5 +99,4 @@ });

matches(
`import { empty, notEmpty as foo } from '@ember/object/computed';`,
`var empty = Ember.computed.empty;
var foo = Ember.computed.notEmpty;`
`import { empty, notEmpty as foo } from '@ember/object/computed';var _x = empty;var _y = foo;`,
`var _x = Ember.computed.empty;var _y = Ember.computed.notEmpty;`
);

@@ -90,4 +108,4 @@ });

matches(
`import { default as foo } from '@ember/component';`,
`var foo = Ember.Component;`
`import { default as foo } from '@ember/component';var _x = foo;`,
`var _x = Ember.Component;`
);

@@ -164,3 +182,3 @@ });

it(`allows blacklisting specific named imports`, assert => {
let input = `import { assert, inspect } from '@ember/debug';`;
let input = `import { assert, inspect } from '@ember/debug';var _x = inspect`;
let actual = transform(input, [

@@ -170,7 +188,7 @@ [Plugin, { blacklist: { '@ember/debug': ['assert', 'warn', 'deprecate'] } }],

assert.equal(actual, `import { assert } from '@ember/debug';\nvar inspect = Ember.inspect;`);
assert.equal(actual, `import { assert } from '@ember/debug';var _x = Ember.inspect;`);
});
it('does not error when a blacklist is not present', assert => {
let input = `import { assert, inspect } from '@ember/debug';`;
let input = `import { assert, inspect } from '@ember/debug';var _x = assert; var _y = inspect;`;
let actual = transform(input, [

@@ -180,3 +198,3 @@ [Plugin, { blacklist: { } }],

assert.equal(actual, `var assert = Ember.assert;\nvar inspect = Ember.inspect;`);
assert.equal(actual, `var _x = Ember.assert;var _y = Ember.inspect;`);
});

@@ -188,12 +206,12 @@ });

matches(
`import Ember from 'ember';`,
``
`import Ember from 'ember';var _x = Ember;`,
`var _x = Ember;`
);
matches(
`import Em from 'ember';`,
`var Em = Ember;`
`import Em from 'ember'; var _x = Em;`,
`var _x = Ember;`
);
matches(
`import Asdf from 'ember';`,
`var Asdf = Ember;`
`import Asdf from 'ember';var _x = Asdf;`,
`var _x = Ember;`
);

@@ -200,0 +218,0 @@ matches(

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc