Skip to content

Commit

Permalink
Merge pull request #230 from slorber/master
Browse files Browse the repository at this point in the history
Replace babel-5 parser with retrocompatible babylon setup
  • Loading branch information
cpojer authored Dec 7, 2017
2 parents 2bed715 + c9be2ed commit 07ddf69
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 414 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"license": "BSD-3-Clause",
"dependencies": {
"async": "^1.5.0",
"babel-core": "^5",
"babel-plugin-transform-flow-strip-types": "^6.8.0",
"babel-preset-es2015": "^6.9.0",
"babel-preset-stage-1": "^6.5.0",
Expand Down
42 changes: 42 additions & 0 deletions parser/babel5Compat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/

'use strict';

const babylon = require('babylon');

// These are the options that were the default of the Babel5 parse function
// see https://github.com/babel/babel/blob/5.x/packages/babel/src/api/node.js#L81
const options = {
sourceType: 'module',
allowHashBang: true,
ecmaVersion: Infinity,
allowImportExportEverywhere: true,
allowReturnOutsideFunction: true,
plugins: [
'estree',
'jsx',
'asyncGenerators',
'classProperties',
'doExpressions',
'exportExtensions',
'functionBind',
'functionSent',
'objectRestSpread',
'dynamicImport',
],
};

/**
* Wrapper to set default options
*/
exports.parse = function parse (code) {
return babylon.parse(code, options);
};
4 changes: 2 additions & 2 deletions src/collections/__tests__/JSXElement-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

'use strict';

const babel = require('babel-core');
const getParser = require('./../../getParser');

describe('JSXCollection API', function() {
let nodes;
Expand Down Expand Up @@ -40,7 +40,7 @@ describe('JSXCollection API', function() {
' </Child>',
' <Child id="2" foo="baz"/>',
'</FooBar>'
].join('\n'), {parser: babel}).program];
].join('\n'), {parser: getParser()}).program];
});

describe('Traversal', function() {
Expand Down
5 changes: 3 additions & 2 deletions src/collections/__tests__/VariableDeclarator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

'use strict';

const babel = require('babel-core');
const getParser = require('./../../getParser');

const recast = require('recast');
const types = recast.types.namedTypes;
const b = recast.types.builders;
Expand Down Expand Up @@ -53,7 +54,7 @@ describe('VariableDeclarators', function() {
' blah() {}',
' }',
'}',
].join('\n'), {parser: babel}).program];
].join('\n'), {parser: getParser()}).program];
});

describe('Traversal', function() {
Expand Down
2 changes: 1 addition & 1 deletion src/getParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ module.exports = function getParser(parserName) {
return require('../parser/flow');
case 'babel':
default:
return require('babel-core');
return require('../parser/babel5Compat');
}
};
Loading

0 comments on commit 07ddf69

Please sign in to comment.