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

🏗✨ Upgrade to Babel 7 #18574

Merged
merged 15 commits into from
Oct 10, 2018
15 changes: 0 additions & 15 deletions .babelrc

This file was deleted.

43 changes: 26 additions & 17 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,9 @@
"sourceType": "module"
},
"globals": {
"it": false,
"chai": false,
"expect": false,
"describe": false,
"beforeEach": false,
"afterEach": false,
"before": false,
"after": false,
"AMP": false,
"assert": false,
"sinon": true,
"sandbox": true,
"context": false,
"global": false,
"describes": true,
"allowConsoleError": false,
"expectAsyncConsoleError": false,
"restoreAsyncErrorThrows": false,
"stubAsyncErrorThrows": false
"global": false
},
"settings": {
"jsdoc": {
Expand Down Expand Up @@ -190,6 +174,31 @@
"jsdoc/require-param-name": 0,
"jsdoc/require-param-type": 0,
"jsdoc/require-returns-type": 0
},
"globals": {
"it": false,
"chai": false,
"expect": false,
"describe": false,
"beforeEach": false,
"afterEach": false,
"before": false,
"after": false,
"assert": false,
"sinon": true,
"sandbox": true,
"describes": true,
"allowConsoleError": false,
"expectAsyncConsoleError": false,
"restoreAsyncErrorThrows": false,
"stubAsyncErrorThrows": false
}
},
{
"files": ["babel.config.js"],
"globals": {
"module": false,
"process": false
}
}
]
Expand Down
53 changes: 53 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
kristoferbaxter marked this conversation as resolved.
Show resolved Hide resolved
* Copyright 2018 The AMP HTML Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS-IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @fileoverview Global configuration file for the babelify transform.
*
* Notes: From https://babeljs.io/docs/en/plugins#plugin-ordering:
* 1. Plugins run before Presets.
* 2. Plugin ordering is first to last.
* 3. Preset ordering is reversed (last to first).
*/

'use strict';

const minimist = require('minimist');
const argv = minimist(process.argv.slice(2));

module.exports = function(api) {
api.cache(true);
if (argv.single_pass) {
return {};
}
return {
'presets': [
['@babel/env', {
'modules': 'commonjs',
'loose': true,
'targets': {
'browsers': process.env.TRAVIS ?
['Last 2 versions', 'safari >= 9'] : ['Last 2 versions'],
},
}],
],
'compact': false,
'sourceType': 'module',
'ignore': [
'./third_party/closure-library/sha384-generated.js',
],
};
};
9 changes: 5 additions & 4 deletions build-system/get-dep-graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
* limitations under the License.
*/

const babel = require('babel-core');
const babel = require('@babel/core');
const babelify = require('babelify');
const browserify = require('browserify');
const ClosureCompiler = require('google-closure-compiler').compiler;
const colors = require('ansi-colors');
const conf = require('./build.conf');
const devnull = require('dev-null');
const fs = require('fs-extra');
const log = require('fancy-log');
const minimist = require('minimist');
const move = require('glob-move');
const path = require('path');
Expand Down Expand Up @@ -265,7 +266,6 @@ exports.getGraph = function(entryModules, config) {
// The second stage are transforms that closure compiler supports
// directly and which we don't want to apply during deps finding.
.transform(babelify, {
babelrc: false,
compact: false,
plugins: [
require.resolve('babel-plugin-transform-es2015-modules-commonjs'),
Expand Down Expand Up @@ -385,7 +385,9 @@ function setupBundles(graph) {
* @param {!Object} config
*/
function transformPathsToTempDir(graph, config) {
console/*OK*/.log(colors.green(`temp directory ${graph.tmp}`));
if (!process.env.TRAVIS) {
log('Writing transforms to', colors.cyan(graph.tmp));
}
// `sorted` will always have the files that we need.
graph.sorted.forEach(f => {
// Don't transform node_module files for now and just copy it.
Expand All @@ -394,7 +396,6 @@ function transformPathsToTempDir(graph, config) {
} else {
const {code} = babel.transformFileSync(f, {
plugins: conf.plugins(config.define.indexOf['ESM_BUILD=true'] !== -1),
babelrc: false,
retainLines: true,
});
fs.outputFileSync(`${graph.tmp}/${f}`, code);
Expand Down
42 changes: 0 additions & 42 deletions build-system/tasks/compile-access-expr.js

This file was deleted.

44 changes: 0 additions & 44 deletions build-system/tasks/compile-bind-expr.js

This file was deleted.

44 changes: 0 additions & 44 deletions build-system/tasks/compile-css-expr.js

This file was deleted.

85 changes: 85 additions & 0 deletions build-system/tasks/compile-expr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/**
* Copyright 2018 The AMP HTML Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS-IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';

const fs = require('fs-extra');
const gulp = require('gulp');
const jison = require('jison');

/**
* Helper function that uses jison to generate a parser for the input file.
* @param {string} path
* @param {string} jisonFilename
* @param {string} imports
* @param {string} parserName
* @param {string} jsFilename
*/
function compileExpr(path, jisonFilename, imports, parserName, jsFilename) {
const bnf = fs.readFileSync(path + jisonFilename, 'utf8');
const settings = {
type: 'lalr',
debug: false,
moduleType: 'js',
'token-stack': true,
rsimha marked this conversation as resolved.
Show resolved Hide resolved
};
const generator = new jison.Generator(bnf, settings);
const jsModule = generator.generate(settings);

const license = fs.readFileSync(
'build-system/tasks/js-license.txt', 'utf8');
const suppressCheckTypes = '/** @fileoverview ' +
rsimha marked this conversation as resolved.
Show resolved Hide resolved
'@suppress {checkTypes, suspiciousCode, uselessCode} */';
const jsExports = 'export const ' + parserName + ' = parser;';
rsimha marked this conversation as resolved.
Show resolved Hide resolved

const out = [
license,
suppressCheckTypes,
imports,
jsModule,
jsExports].join('\n\n') + '\n';
rsimha marked this conversation as resolved.
Show resolved Hide resolved
fs.writeFileSync(path + jsFilename, out);
rsimha marked this conversation as resolved.
Show resolved Hide resolved
}

function compileAccessExpr() {
const path = 'extensions/amp-access/0.1/';
const jisonFilename = 'access-expr-impl.jison';
const imports = '';
const parserName = 'accessParser';
const jsFilename = 'access-expr-impl.js';
compileExpr(path, jisonFilename, imports, parserName, jsFilename);
}

function compileBindExpr() {
const path = 'extensions/amp-bind/0.1/';
const jisonFilename = 'bind-expr-impl.jison';
const imports = 'import {AstNode, AstNodeType} from \'./bind-expr-defines\';';
const parserName = 'bindParser';
const jsFilename = 'bind-expr-impl.js';
compileExpr(path, jisonFilename, imports, parserName, jsFilename);
}

function compileCssExpr() {
const path = 'extensions/amp-animation/0.1/';
const jisonFilename = 'css-expr-impl.jison';
const imports = 'import * as ast from \'./css-expr-ast\';';
const parserName = 'cssParser';
const jsFilename = 'bind-expr-impl.js';
compileExpr(path, jisonFilename, imports, parserName, jsFilename);
}

gulp.task('compile-access-expr', compileAccessExpr);
gulp.task('compile-bind-expr', compileBindExpr);
gulp.task('compile-css-expr', compileCssExpr);
Loading