Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(compiler): migrate referential integrity into lwc-compiler #109

Merged
merged 12 commits into from
Feb 15, 2018
13 changes: 7 additions & 6 deletions packages/lwc-compiler/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-env node */

module.exports = {
testMatch: [
'**/?(*.)(spec|test).js'
]
}
testRegex: "\\.spec\\.(js|ts)$",
transform: {
"^.+\\.(js|ts)$": "ts-jest"
},
moduleFileExtensions: ["ts", "js", "json", "node"],
};

9 changes: 8 additions & 1 deletion packages/lwc-compiler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"license": "ISC",
"scripts": {
"clean": "rimraf dist/",
"build": "babel src/ --out-dir dist/commonjs",
"build": "tsc",
"build:umd": "webpack --progress",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will probably need to keep the build:umd for now until we update the delivery mechanism of the compiler into Aura.

"test": "jest --coverage --maxWorkers=2"
},
Expand All @@ -17,6 +17,9 @@
"power-assert": "^1.4.2",
"rimraf": "^2.6.1",
"string-replace-webpack-plugin": "0.1.3",
"ts-jest": "^21.2.4",
"tslint": "^5.2.0",
"typescript": "^2.7.1",
"webpack": "^3.7.1",
"webpack-closure-compiler": "2.1.5"
},
Expand Down Expand Up @@ -55,10 +58,14 @@
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.6.0",
"babel-preset-minify": "~0.2.0",
"babel-traverse": "^6.26.0",
"babylon": "^6.18.0",
"cssnano": "^3.10.0",
"lwc-template-compiler": "0.17.15",
"parse5": "^3.0.3",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you make sure the versions of the packages align with the other packages?
For example ts-jest is not in sync with the other package, and it causes new entries to be added in the yarn.lock

"postcss": "^6.0.13",
"postcss-plugin-lwc": "0.17.15",
"postcss-selector-parser": "^3.1.1",
"rollup": "0.50.0",
"rollup-plugin-babel": "^3.0.2",
"rollup-plugin-replace": "^2.0.0"
Expand Down
25 changes: 25 additions & 0 deletions packages/lwc-compiler/src/__tests__/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
const { compile, transform } = require('../index');
const { pretify } = require('./utils');

const VALID_TEST_JS = `
import label from '@label/mylabel';
function isTrue() {
return label;
}
isTrue();
`.trim();

describe('compile', () => {
it('should validate entry type', () => {
expect(() => compile()).toThrow(/Expected a string for entry/);
Expand All @@ -29,6 +37,23 @@ describe('compile', () => {
/in-memory module resolution expects values to be string. Received true for key \/x\/foo\/foo.js/,
);
});
// TODO: uncomment once compile output format changes
// it.only('should return status, diagnostics, references, and bundles', () => {
// const config = {
// sources: {
// '/x/foo/foo.js': VALID_TEST_JS,
// },
// entry: '/x/foo/foo.js',
// moduleName: 'foo',
// moduleNamespace: 'x',
// format: 'whoknows',
// };
// const { status, diagnostics, references, bundles } = compile();
// expect(status).toBe('ok');
// expect(diagnostics.length).toBe(0);
// expect(references.length > 0).toBe(true);
// expect(bundles.length).toBe(1);
// });
});

describe('transform', () => {
Expand Down
50 changes: 25 additions & 25 deletions packages/lwc-compiler/src/babel-plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,37 +35,37 @@
*/

// ES2015 support
import constants from 'babel-plugin-check-es2015-constants';
import arrowFunctions from 'babel-plugin-transform-es2015-arrow-functions';
import blockScoped from 'babel-plugin-transform-es2015-block-scoped-functions';
import blockScoping from 'babel-plugin-transform-es2015-block-scoping';
import esClasses from 'babel-plugin-transform-es2015-classes';
import computedProps from 'babel-plugin-transform-es2015-computed-properties';
import destructuring from 'babel-plugin-transform-es2015-destructuring';
import duplicatedKeys from 'babel-plugin-transform-es2015-duplicate-keys';
import forOf from 'babel-plugin-transform-es2015-for-of';
import strLiterals from 'babel-plugin-transform-es2015-literals';
import objSuper from 'babel-plugin-transform-es2015-object-super';
import parameters from 'babel-plugin-transform-es2015-parameters';
import shorthand from 'babel-plugin-transform-es2015-shorthand-properties';
import spread from 'babel-plugin-transform-es2015-spread';
import stickyRegex from 'babel-plugin-transform-es2015-sticky-regex';
import templateLiterals from 'babel-plugin-transform-es2015-template-literals';
import typeofSymbol from 'babel-plugin-transform-es2015-typeof-symbol';
import uniRegex from 'babel-plugin-transform-es2015-unicode-regex';
import * as constants from 'babel-plugin-check-es2015-constants';
import * as arrowFunctions from 'babel-plugin-transform-es2015-arrow-functions';
import * as blockScoped from 'babel-plugin-transform-es2015-block-scoped-functions';
import * as blockScoping from 'babel-plugin-transform-es2015-block-scoping';
import * as esClasses from 'babel-plugin-transform-es2015-classes';
import * as computedProps from 'babel-plugin-transform-es2015-computed-properties';
import * as destructuring from 'babel-plugin-transform-es2015-destructuring';
import * as duplicatedKeys from 'babel-plugin-transform-es2015-duplicate-keys';
import * as forOf from 'babel-plugin-transform-es2015-for-of';
import * as strLiterals from 'babel-plugin-transform-es2015-literals';
import * as objSuper from 'babel-plugin-transform-es2015-object-super';
import * as parameters from 'babel-plugin-transform-es2015-parameters';
import * as shorthand from 'babel-plugin-transform-es2015-shorthand-properties';
import * as spread from 'babel-plugin-transform-es2015-spread';
import * as stickyRegex from 'babel-plugin-transform-es2015-sticky-regex';
import * as templateLiterals from 'babel-plugin-transform-es2015-template-literals';
import * as typeofSymbol from 'babel-plugin-transform-es2015-typeof-symbol';
import * as uniRegex from 'babel-plugin-transform-es2015-unicode-regex';

// Async/Await support
import asyncGenerator from 'babel-plugin-transform-async-to-generator';
import regenerator from 'babel-plugin-transform-regenerator';
import transformRuntime from 'babel-plugin-transform-runtime';
import * as asyncGenerator from 'babel-plugin-transform-async-to-generator';
import * as regenerator from 'babel-plugin-transform-regenerator';
import * as transformRuntime from 'babel-plugin-transform-runtime';

// ES2015+ support
import trailingCommas from 'babel-plugin-syntax-trailing-function-commas';
import expOperator from 'babel-plugin-transform-exponentiation-operator';
import * as trailingCommas from 'babel-plugin-syntax-trailing-function-commas';
import * as expOperator from 'babel-plugin-transform-exponentiation-operator';

// Non-standard transformations
import objectRestSpread from 'babel-plugin-transform-object-rest-spread';
import publicFieldsPlugin from 'babel-plugin-transform-class-properties';
import * as objectRestSpread from 'babel-plugin-transform-object-rest-spread';
import * as publicFieldsPlugin from 'babel-plugin-transform-class-properties';

const looseOpts = {
loose: false,
Expand Down
2 changes: 1 addition & 1 deletion packages/lwc-compiler/src/bundle.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { rollup } from 'rollup';
import rollupPluginReplace from 'rollup-plugin-replace';
import * as rollupPluginReplace from 'rollup-plugin-replace';

import { isCompat, isProd } from './modes';

Expand Down
33 changes: 33 additions & 0 deletions packages/lwc-compiler/src/diagnostics/diagnostic-collector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Diagnostic, DiagnosticLevel } from './diagnostic';

export class DiagnosticCollector {
private diagnostics: Diagnostic[] = [];

constructor(diagnostics?: Diagnostic[]) {
if (diagnostics) {
this.addAll(diagnostics);
}
}
public getAll() {
return this.diagnostics;
}

public addAll(items: Diagnostic[]) {
if (!Array.isArray(items)) {
return;
}
for (const item of items) {
this.add(item);
}
}

public add(item: Diagnostic) {
this.diagnostics.push(item);
}

public hasError() {
return this.diagnostics.some(d => {
return d.level <= DiagnosticLevel.Error;
});
}
}
35 changes: 35 additions & 0 deletions packages/lwc-compiler/src/diagnostics/diagnostic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
export interface Diagnostic {
/** Level of the diagnostic */
level: DiagnosticLevel;

/** Relative path location of the file in the bundle. */
filename: string;

/** Error messages that should be outputed */
message: string;

/**
* Location in the code affected by the diagnostic.
* This field is optional, for example when the compiler throws an uncaught exception.
*/
location?: Location;
}

export enum DiagnosticLevel {
/** Unexpected error, parsing error, bundling error */
Fatal = 0,
/** Linting error with error level, invalid external reference, invalid import, invalid transform */
Error = 1,
/** Linting error with warning level, usage of an API to be deprecated */
Warning = 2,
/** Logging messages */
Log = 3,
}

export interface Location {
/** 0-base character index in the file */
start: number;

/** Number of character after the start index */
length: number;
}
2 changes: 1 addition & 1 deletion packages/lwc-compiler/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import transformFile from './transform';
import { MODES, ALL_MODES, isCompat, isProd } from './modes';
import { zipObject, isUndefined, isString } from './utils';

import replacePlugin from "rollup-plugin-replace";
import * as replacePlugin from "rollup-plugin-replace";
import fsModuleResolver from './module-resolvers/fs';
import inMemoryModuleResolver from './module-resolvers/in-memory';
import minifyPlugin from "./rollup-plugins/minify";
Expand Down
4 changes: 4 additions & 0 deletions packages/lwc-compiler/src/lwc-bundle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface LwcBundle {
entry: string;
sources: [{ filename: string }];
}
Loading