Skip to content

Commit

Permalink
feat: remove backwards compatibility support for "engine" (#721)
Browse files Browse the repository at this point in the history
* feat: revert backwards compatibility support for "engine"
  • Loading branch information
apapko authored Oct 11, 2018
1 parent 81e8c2b commit e312f54
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,15 @@ describe('Element import', () => {
export default class Test extends Component {}
`, {
output: {
code: `import _tmpl from "./test.html";
import { LightningElement as Component } from 'lwc';
export default class Test extends Component {
render() {
return _tmpl;
}
code: `
import _tmpl from "./test.html";
import { LightningElement as Component } from 'lwc';
export default class Test extends Component {
render() {
return _tmpl;
}
}`
}`
}
});
});
Expand Down Expand Up @@ -84,29 +85,43 @@ describe('render method', () => {
export default class Test extends LightningElement {}
`, {
output: {
code: `import _tmpl from "./test.html";
import { LightningElement } from "lwc";
export default class Test extends LightningElement {
render() {
return _tmpl;
}
code: `
import _tmpl from "./test.html";
import { LightningElement } from "lwc";
export default class Test extends LightningElement {
render() {
return _tmpl;
}
}`
}`
}
});

describe('does not insert render method when extending from legacy "engine" Element', () => {
pluginTest('inject render method', `
import { Element } from "engine";
export default class Test extends Element {}
`, {
output: {
code: `
import { Element } from "engine";
export default class Test extends Element {}`
}
});

pluginTest(`keep the render method if present`, `
import { LightningElement } from "lwc";
export default class Test extends LightningElement {
render() {}
}
`, {
output: {
code: `import { LightningElement } from "lwc";
export default class Test extends LightningElement {
render() {}
code: `
import { LightningElement } from "lwc";
export default class Test extends LightningElement {
render() {}
}`
}`
}
});

Expand All @@ -118,17 +133,18 @@ export default class Test extends LightningElement {
export default class Test2 extends LightningElement {}
`, {
output: {
code: `import _tmpl from "./test.html";
import { LightningElement } from 'lwc';
code: `
import _tmpl from "./test.html";
import { LightningElement } from 'lwc';
class Test1 extends LightningElement {}
class Test1 extends LightningElement {}
export default class Test2 extends LightningElement {
render() {
return _tmpl;
}
export default class Test2 extends LightningElement {
render() {
return _tmpl;
}
}`
}`
}
})
});
Expand Down Expand Up @@ -459,5 +475,4 @@ describe('metadata', () => {
}
}
);

});
2 changes: 1 addition & 1 deletion packages/babel-plugin-transform-lwc-class/src/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = function ({ types: t }) {

// Store on state local identifiers referencing engine base component
state.componentBaseClassImports = engineImportSpecifiers.filter(({ name }) => (
name === LWC_PACKAGE_EXPORTS.BASE_COMPONENT || name === LWC_PACKAGE_EXPORTS.BASE_COMPONENT_LEGACY
name === LWC_PACKAGE_EXPORTS.BASE_COMPONENT
)).map(({ path }) => (
path.get('local')
));
Expand Down
3 changes: 0 additions & 3 deletions packages/babel-plugin-transform-lwc-class/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@ const DISALLOWED_PROP_SET = new Set([
]);

const LWC_PACKAGE_ALIAS = 'lwc';
const LWC_PACKAGE_ALIAS_LEGACY = 'engine';

const LWC_PACKAGE_EXPORTS = {
BASE_COMPONENT_LEGACY: 'Element',
BASE_COMPONENT: 'LightningElement',
API_DECORATOR: 'api',
TRACK_DECORATOR: 'track',
Expand Down Expand Up @@ -86,7 +84,6 @@ module.exports = {
GLOBAL_ATTRIBUTE_MAP,
LWC_DECORATORS,
LWC_PACKAGE_ALIAS,
LWC_PACKAGE_ALIAS_LEGACY,
LWC_PACKAGE_EXPORTS,

LWC_COMPONENT_PROPERTIES,
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-plugin-transform-lwc-class/src/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { LWC_PACKAGE_ALIAS, LWC_PACKAGE_ALIAS_LEGACY, LWC_PACKAGE_EXPORTS } = require('./constants');
const { LWC_PACKAGE_ALIAS, LWC_PACKAGE_EXPORTS } = require('./constants');

function findClassMethod(path, name, properties = {}) {
path.assertClassBody();
Expand Down Expand Up @@ -46,7 +46,7 @@ function getEngineImportsStatements(path) {

return programPath.get('body').filter(node => {
const source = node.get('source');
return node.isImportDeclaration() && (source.isStringLiteral({ value: LWC_PACKAGE_ALIAS }) || source.isStringLiteral({ value: LWC_PACKAGE_ALIAS_LEGACY }))
return node.isImportDeclaration() && (source.isStringLiteral({ value: LWC_PACKAGE_ALIAS }))
});
}

Expand Down
1 change: 0 additions & 1 deletion packages/lwc-engine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
},
"lwc": {
"modules": {
"engine": "dist/modules/es2017/engine.js",
"lwc": "dist/modules/es2017/engine.js"
}
},
Expand Down
2 changes: 1 addition & 1 deletion packages/lwc-jest-resolver/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function getLwcPath(path) {

if (lwcMap[path]) {
// Handle magic LWC imports
if (path === 'lwc' || /* deprecated */ path === 'engine') {
if (path === 'lwc') {
return require.resolve('lwc-engine');
} else if (path === 'wire-service') {
return require.resolve('lwc-wire-service');
Expand Down

0 comments on commit e312f54

Please sign in to comment.