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

Cherry-pick jstransform, strip-types upgrades and re-shrinkwrap #2543

Merged
merged 4 commits into from
Nov 17, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var visitors = require('./vendor/fbtransform/visitors');
var transform = require('jstransform').transform;
var typesSyntax = require('jstransform/visitors/type-syntax');
var Buffer = require('buffer').Buffer;

module.exports = {
Expand Down Expand Up @@ -37,7 +38,11 @@ function innerTransform(input, options) {
visitorSets.push('harmony');
}
if (options.stripTypes) {
visitorSets.push('type-annotations');
// Stripping types needs to happen before the other transforms
// unfortunately, due to bad interactions. For example,
// es6-rest-param-visitors conflict with stripping rest param type
// annotation
input = transform(typesSyntax.visitorList, input, options).code;
}

var visitorList = visitors.getVisitorsBySet(visitorSets);
Expand Down
1,247 changes: 639 additions & 608 deletions npm-shrinkwrap.json

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
},
"dependencies": {
"commoner": "^0.10.0",
"esprima-fb": "^6001.1.0-dev-harmony-fb",
"jstransform": "^6.3.2"
"jstransform": "^8.0.0"
},
"devDependencies": {
"benchmark": "~1.0.0",
Expand Down
12 changes: 12 additions & 0 deletions vendor/browser-transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

var buffer = require('buffer');
var transform = require('jstransform').transform;
var typesSyntax = require('jstransform/visitors/type-syntax');
var visitors = require('./fbtransform/visitors');

var headEl;
Expand Down Expand Up @@ -42,6 +43,14 @@ function transformReact(source, options) {
visitorList = visitors.transformVisitors.react;
}

if (options.stripTypes) {
// Stripping types needs to happen before the other transforms
// unfortunately, due to bad interactions. For example,
// es6-rest-param-visitors conflict with stripping rest param type
// annotation
source = transform(typesSyntax.visitorList, source, options).code;
}

return transform(visitorList, source, {
sourceMap: supportsAccessors && options.sourceMap
});
Expand Down Expand Up @@ -240,6 +249,9 @@ function loadScripts(scripts) {
if (/;harmony=true(;|$)/.test(script.type)) {
options.harmony = true
}
if (/;stripTypes=true(;|$)/.test(script.type)) {
options.stripTypes = true;
}

// script.async is always true for non-javascript script tags
var async = script.hasAttribute('async');
Expand Down
7 changes: 7 additions & 0 deletions vendor/fbtransform/syntax.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"use strict";

var transform = require('jstransform').transform;
var typesSyntax = require('jstransform/visitors/type-syntax');
var visitors = require('./visitors');

/**
Expand All @@ -16,6 +17,12 @@ var visitors = require('./visitors');
function transformAll(source, options, excludes) {
excludes = excludes || [];

// Stripping types needs to happen before the other transforms
// unfortunately, due to bad interactions. For example,
// es6-rest-param-visitors conflict with stripping rest param type
// annotation
source = transform(typesSyntax.visitorList, source, options).code;

// The typechecker transform must run in a second pass in order to operate on
// the entire source code -- so exclude it from the first pass
var visitorsList = visitors.getAllVisitors(excludes.concat('typechecker'));
Expand Down
2 changes: 1 addition & 1 deletion vendor/fbtransform/transforms/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/*global exports:true*/
"use strict";

var Syntax = require('esprima-fb').Syntax;
var Syntax = require('jstransform').Syntax;
var utils = require('jstransform/src/utils');

var FALLBACK_TAGS = require('./xjs').knownTags;
Expand Down
2 changes: 1 addition & 1 deletion vendor/fbtransform/transforms/reactDisplayName.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/*global exports:true*/
"use strict";

var Syntax = require('esprima-fb').Syntax;
var Syntax = require('jstransform').Syntax;
var utils = require('jstransform/src/utils');

function addDisplayName(displayName, object, state) {
Expand Down
2 changes: 1 addition & 1 deletion vendor/fbtransform/transforms/xjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/
/*global exports:true*/
"use strict";
var Syntax = require('esprima-fb').Syntax;
var Syntax = require('jstransform').Syntax;
var utils = require('jstransform/src/utils');

var knownTags = {
Expand Down
8 changes: 1 addition & 7 deletions vendor/fbtransform/visitors.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ var es6Templates = require('jstransform/visitors/es6-template-visitors');
var es7SpreadProperty = require('jstransform/visitors/es7-spread-property-visitors');
var react = require('./transforms/react');
var reactDisplayName = require('./transforms/reactDisplayName');
var typesSyntax = require('jstransform/visitors/type-syntax');

/**
* Map from transformName => orderedListOfVisitors.
Expand All @@ -23,8 +22,7 @@ var transformVisitors = {
'es6-rest-params': es6RestParameters.visitorList,
'es6-templates': es6Templates.visitorList,
'es7-spread-property': es7SpreadProperty.visitorList,
'react': react.visitorList.concat(reactDisplayName.visitorList),
'types': typesSyntax.visitorList
'react': react.visitorList.concat(reactDisplayName.visitorList)
};

var transformSets = {
Expand All @@ -40,17 +38,13 @@ var transformSets = {
],
'react': [
'react'
],
'type-annotations': [
'types'
]
};

/**
* Specifies the order in which each transform should run.
*/
var transformRunOrder = [
'types',
'es6-arrow-functions',
'es6-object-concise-method',
'es6-object-short-notation',
Expand Down