Merge branch 'master' into development

This commit is contained in:
Sebastian McKenzie 2015-07-21 02:28:00 +01:00
commit 956fd8d770
15 changed files with 283 additions and 6 deletions

View File

@ -72,6 +72,12 @@ Use the `TEST_GREP` variable to run a subset of tests by name:
$ TEST_GREP=transformation make test
```
To test the code coverage, use:
```sh
$ make test-cov
```
#### Internals
Please see [`/doc`](/doc) for internals documentation relevant to developing babel.

View File

@ -177,6 +177,12 @@ export function NullableTypeAnnotation(node, print) {
print.plain(node.typeAnnotation);
}
/**
* Prints NumberLiteralTypeAnnotation, prints value.
*/
export { Literal as NumberLiteralTypeAnnotation } from "./types";
/**
* Prints NumberTypeAnnotation.
*/

View File

@ -407,6 +407,30 @@ export default class File {
return uid;
}
addTemplateObject(helperName: string, strings: Array, raw: Array): Object {
// Generate a unique name based on the string literals so we dedupe
// identical strings used in the program.
var stringIds = raw.elements.map(function(string) {
return string.value;
});
var name = `${helperName}_${raw.elements.length}_${stringIds.join(",")}`;
var declar = this.declarations[name];
if (declar) return declar;
var uid = this.declarations[name] = this.scope.generateUidIdentifier("templateObject");
var helperId = this.addHelper(helperName);
var init = t.callExpression(helperId, [strings, raw]);
init._compact = true;
this.scope.push({
id: uid,
init: init,
_blockHoist: 1.9 // This ensures that we don't fail if not using function expression helpers
});
return uid;
}
/**
* [Please add a description.]
*/

View File

@ -110,7 +110,7 @@ export default class Pipeline {
}
/**
* [Please add a description.]
* Build dependency graph by recursing `metadata.modules`. WIP.
*/
pretransform(code: string, opts?: Object) {

View File

@ -64,7 +64,9 @@ export var visitor = {
var templateName = "tagged-template-literal";
if (file.isLoose("es6.templateLiterals")) templateName += "-loose";
args.push(t.callExpression(file.addHelper(templateName), [strings, raw]));
var templateObject = file.addTemplateObject(templateName, strings, raw);
args.push(templateObject);
args = args.concat(quasi.expressions);

View File

@ -834,14 +834,15 @@ export default class Scope {
var unique = opts.unique;
var kind = opts.kind || "var";
var blockHoist = opts._blockHoist == null ? 2 : opts._blockHoist;
var dataKey = `declaration:${kind}`;
var dataKey = `declaration:${kind}:${blockHoist}`;
var declar = !unique && path.getData(dataKey);
if (!declar) {
declar = t.variableDeclaration(kind, []);
declar._generated = true;
declar._blockHoist = 2;
declar._blockHoist = blockHoist;
this.hub.file.attachAuxiliaryComment(declar);

View File

@ -82,6 +82,10 @@ define("NullableTypeAnnotation", {
aliases: ["Flow"]
});
define("NumberLiteralTypeAnnotation", {
aliases: ["Flow"]
});
define("NumberTypeAnnotation", {
aliases: ["Flow", "FlowBaseAnnotation"]
});

View File

@ -4,6 +4,7 @@ var buildExternalHelpers = require("../lib/tools/build-external-helpers");
var PluginManager = require("../lib/transformation/file/plugin-manager");
var Transformer = require("../lib/transformation/transformer");
var transform = require("../lib/transformation");
var Pipeline = require("../lib/transformation/pipeline");
var assert = require("assert");
var File = require("../lib/transformation/file");
@ -422,6 +423,11 @@ suite("api", function () {
assert.ok(file2.opts.extra !== file3.opts.extra);
});
// For now just signal that it's not cruft and shouldn't be deleted.
test("pretransform exists", function () {
assert.ok(Pipeline.prototype.pretransform);
});
suite("buildExternalHelpers", function () {
test("all", function () {
var script = buildExternalHelpers();

View File

@ -0,0 +1,5 @@
var a: 123;
var a: 123.0;
var a: 0x7B;
var a: 0b1111011;
var a: 0o173;

View File

@ -0,0 +1,5 @@
var a: 123;
var a: 123.0;
var a: 0x7B;
var a: 123;
var a: 123;

View File

@ -1 +1,3 @@
var foo = bar`wow\na${ 42 }b ${_.foobar()}`;
var bar = bar`wow\nab${ 42 } ${_.foobar()}`;
var bar = bar`wow\naB${ 42 } ${_.baz()}`;

View File

@ -1,5 +1,11 @@
"use strict";
var _templateObject = _taggedTemplateLiteralLoose(["wow\na", "b ", ""], ["wow\\na", "b ", ""]),
_templateObject2 = _taggedTemplateLiteralLoose(["wow\nab", " ", ""], ["wow\\nab", " ", ""]),
_templateObject3 = _taggedTemplateLiteralLoose(["wow\naB", " ", ""], ["wow\\naB", " ", ""]);
function _taggedTemplateLiteralLoose(strings, raw) { strings.raw = raw; return strings; }
var foo = bar(_taggedTemplateLiteralLoose(["wow\na", "b ", ""], ["wow\\na", "b ", ""]), 42, _.foobar());
var foo = bar(_templateObject, 42, _.foobar());
var bar = bar(_templateObject2, 42, _.foobar());
var bar = bar(_templateObject3, 42, _.baz());

View File

@ -1,5 +1,7 @@
"use strict";
var _templateObject = _taggedTemplateLiteral(["wow\na", "b ", ""], ["wow\\na", "b ", ""]);
function _taggedTemplateLiteral(strings, raw) { return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
var foo = bar(_taggedTemplateLiteral(["wow\na", "b ", ""], ["wow\\na", "b ", ""]), 42, _.foobar());
var foo = bar(_templateObject, 42, _.foobar());

View File

@ -493,6 +493,12 @@ pp.flowParsePrimaryType = function () {
this.next();
return this.finishNode(node, "StringLiteralTypeAnnotation");
case tt.num:
node.value = this.value;
node.raw = this.input.slice(this.start, this.end);
this.next();
return this.finishNode(node, "NumberLiteralTypeAnnotation");
default:
if (this.type.keyword === "typeof") {
return this.flowParseTypeofType();

View File

@ -10174,6 +10174,208 @@ var fbTestFixture = {
}
},
},
'Number Literal Types': {
'var a: 123': {
type: 'VariableDeclaration',
declarations: [{
type: 'VariableDeclarator',
id: {
type: 'Identifier',
name: 'a',
typeAnnotation: {
type: 'TypeAnnotation',
typeAnnotation: {
type: 'NumberLiteralTypeAnnotation',
value: 123,
raw: '123',
range: [7, 10],
loc: {
start: { line: 1, column: 7 },
end: { line: 1, column: 10 }
}
},
range: [5, 10],
loc: {
start: { line: 1, column: 5 },
end: { line: 1, column: 10 }
}
}
},
init: null,
range: [4, 10],
loc: {
start: { line: 1, column: 4 },
end: { line: 1, column: 10 }
}
}],
kind: 'var',
range: [0, 10],
loc: {
start: { line: 1, column: 0 },
end: { line: 1, column: 10 }
}
},
'var a: 123.0': {
type: 'VariableDeclaration',
declarations: [{
type: 'VariableDeclarator',
id: {
type: 'Identifier',
name: 'a',
typeAnnotation: {
type: 'TypeAnnotation',
typeAnnotation: {
type: 'NumberLiteralTypeAnnotation',
value: 123,
raw: '123.0',
range: [7, 12],
loc: {
start: { line: 1, column: 7 },
end: { line: 1, column: 12 }
}
},
range: [5, 12],
loc: {
start: { line: 1, column: 5 },
end: { line: 1, column: 12 }
}
}
},
init: null,
range: [4, 12],
loc: {
start: { line: 1, column: 4 },
end: { line: 1, column: 12 }
}
}],
kind: 'var',
range: [0, 12],
loc: {
start: { line: 1, column: 0 },
end: { line: 1, column: 12 }
}
},
'var a: 0x7B': {
type: 'VariableDeclaration',
declarations: [{
type: 'VariableDeclarator',
id: {
type: 'Identifier',
name: 'a',
typeAnnotation: {
type: 'TypeAnnotation',
typeAnnotation: {
type: 'NumberLiteralTypeAnnotation',
value: 123,
raw: '0x7B',
range: [7, 11],
loc: {
start: { line: 1, column: 7 },
end: { line: 1, column: 11 }
}
},
range: [5, 11],
loc: {
start: { line: 1, column: 5 },
end: { line: 1, column: 11 }
}
}
},
init: null,
range: [4, 11],
loc: {
start: { line: 1, column: 4 },
end: { line: 1, column: 11 }
}
}],
kind: 'var',
range: [0, 11],
loc: {
start: { line: 1, column: 0 },
end: { line: 1, column: 11 }
}
},
'var a: 0b1111011': {
type: 'VariableDeclaration',
declarations: [{
type: 'VariableDeclarator',
id: {
type: 'Identifier',
name: 'a',
typeAnnotation: {
type: 'TypeAnnotation',
typeAnnotation: {
type: 'NumberLiteralTypeAnnotation',
value: 123,
raw: '0b1111011',
range: [7, 16],
loc: {
start: { line: 1, column: 7 },
end: { line: 1, column: 16 }
}
},
range: [5, 16],
loc: {
start: { line: 1, column: 5 },
end: { line: 1, column: 16 }
}
}
},
init: null,
range: [4, 16],
loc: {
start: { line: 1, column: 4 },
end: { line: 1, column: 16 }
}
}],
kind: 'var',
range: [0, 16],
loc: {
start: { line: 1, column: 0 },
end: { line: 1, column: 16 }
}
},
'var a: 0o173': {
type: 'VariableDeclaration',
declarations: [{
type: 'VariableDeclarator',
id: {
type: 'Identifier',
name: 'a',
typeAnnotation: {
type: 'TypeAnnotation',
typeAnnotation: {
type: 'NumberLiteralTypeAnnotation',
value: 123,
raw: '0o173',
range: [7, 12],
loc: {
start: { line: 1, column: 7 },
end: { line: 1, column: 12 }
}
},
range: [5, 12],
loc: {
start: { line: 1, column: 5 },
end: { line: 1, column: 12 }
}
}
},
init: null,
range: [4, 12],
loc: {
start: { line: 1, column: 4 },
end: { line: 1, column: 12 }
}
}],
kind: 'var',
range: [0, 12],
loc: {
start: { line: 1, column: 0 },
end: { line: 1, column: 12 }
}
}
},
'Qualified Generic Type': {
'var a : A.B': {
type: 'VariableDeclaration',