ast-types 0.7.4 → 0.7.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.travis.yml +4 -0
- package/def/core.js +18 -1
- package/def/es6.js +14 -2
- package/def/fb-harmony.js +13 -0
- package/lib/types.js +31 -1
- package/package.json +1 -1
package/.travis.yml
CHANGED
package/def/core.js
CHANGED
|
@@ -354,7 +354,24 @@ def("Literal")
|
|
|
354
354
|
null, // isNull would also work here.
|
|
355
355
|
isNumber,
|
|
356
356
|
isRegExp
|
|
357
|
-
))
|
|
357
|
+
))
|
|
358
|
+
.field("regex", or({
|
|
359
|
+
pattern: isString,
|
|
360
|
+
flags: isString
|
|
361
|
+
}, null), function() {
|
|
362
|
+
if (!isRegExp.check(this.value))
|
|
363
|
+
return null;
|
|
364
|
+
|
|
365
|
+
var flags = "";
|
|
366
|
+
if (this.value.ignoreCase) flags += "i";
|
|
367
|
+
if (this.value.multiline) flags += "m";
|
|
368
|
+
if (this.value.global) flags += "g";
|
|
369
|
+
|
|
370
|
+
return {
|
|
371
|
+
pattern: this.value.source,
|
|
372
|
+
flags: flags
|
|
373
|
+
};
|
|
374
|
+
});
|
|
358
375
|
|
|
359
376
|
// Abstract (non-buildable) comment supertype. Not a Node.
|
|
360
377
|
def("Comment")
|
package/def/es6.js
CHANGED
|
@@ -62,6 +62,11 @@ def("ComprehensionBlock")
|
|
|
62
62
|
.field("right", def("Expression"))
|
|
63
63
|
.field("each", isBoolean);
|
|
64
64
|
|
|
65
|
+
def("ModuleSpecifier")
|
|
66
|
+
.bases("Literal")
|
|
67
|
+
.build("value")
|
|
68
|
+
.field("value", isString);
|
|
69
|
+
|
|
65
70
|
def("Property")
|
|
66
71
|
// Esprima extensions not mentioned in the Mozilla Parser API:
|
|
67
72
|
.field("key", or(def("Literal"), def("Identifier"), def("Expression")))
|
|
@@ -205,7 +210,11 @@ def("ExportDeclaration")
|
|
|
205
210
|
def("ExportSpecifier"),
|
|
206
211
|
def("ExportBatchSpecifier")
|
|
207
212
|
)], defaults.emptyArray)
|
|
208
|
-
.field("source", or(
|
|
213
|
+
.field("source", or(
|
|
214
|
+
def("Literal"),
|
|
215
|
+
def("ModuleSpecifier"),
|
|
216
|
+
null
|
|
217
|
+
), defaults["null"]);
|
|
209
218
|
|
|
210
219
|
def("ImportDeclaration")
|
|
211
220
|
.bases("Declaration")
|
|
@@ -215,7 +224,10 @@ def("ImportDeclaration")
|
|
|
215
224
|
def("ImportNamespaceSpecifier"),
|
|
216
225
|
def("ImportDefaultSpecifier")
|
|
217
226
|
)], defaults.emptyArray)
|
|
218
|
-
.field("source",
|
|
227
|
+
.field("source", or(
|
|
228
|
+
def("Literal"),
|
|
229
|
+
def("ModuleSpecifier")
|
|
230
|
+
));
|
|
219
231
|
|
|
220
232
|
def("TaggedTemplateExpression")
|
|
221
233
|
.bases("Expression")
|
package/def/fb-harmony.js
CHANGED
|
@@ -4,6 +4,7 @@ var def = types.Type.def;
|
|
|
4
4
|
var or = types.Type.or;
|
|
5
5
|
var builtin = types.builtInTypes;
|
|
6
6
|
var isString = builtin.string;
|
|
7
|
+
var isNumber = builtin.number;
|
|
7
8
|
var isBoolean = builtin.boolean;
|
|
8
9
|
var defaults = require("../lib/shared").defaults;
|
|
9
10
|
|
|
@@ -114,6 +115,12 @@ def("VoidTypeAnnotation")
|
|
|
114
115
|
def("NumberTypeAnnotation")
|
|
115
116
|
.bases("Type");
|
|
116
117
|
|
|
118
|
+
def("NumberLiteralTypeAnnotation")
|
|
119
|
+
.bases("Type")
|
|
120
|
+
.build("value", "raw")
|
|
121
|
+
.field("value", isNumber)
|
|
122
|
+
.field("raw", isString);
|
|
123
|
+
|
|
117
124
|
def("StringTypeAnnotation")
|
|
118
125
|
.bases("Type");
|
|
119
126
|
|
|
@@ -126,6 +133,12 @@ def("StringLiteralTypeAnnotation")
|
|
|
126
133
|
def("BooleanTypeAnnotation")
|
|
127
134
|
.bases("Type");
|
|
128
135
|
|
|
136
|
+
def("BooleanLiteralTypeAnnotation")
|
|
137
|
+
.bases("Type")
|
|
138
|
+
.build("value", "raw")
|
|
139
|
+
.field("value", isBoolean)
|
|
140
|
+
.field("raw", isString);
|
|
141
|
+
|
|
129
142
|
def("TypeAnnotation")
|
|
130
143
|
.bases("Node")
|
|
131
144
|
.build("typeAnnotation")
|
package/lib/types.js
CHANGED
|
@@ -478,7 +478,7 @@ Dp.build = function(/* param1, param2, ... */) {
|
|
|
478
478
|
// Every buildable type will have its "type" field filled in
|
|
479
479
|
// automatically. This includes types that are not subtypes of Node,
|
|
480
480
|
// like SourceLocation, but that seems harmless (TODO?).
|
|
481
|
-
self.field("type",
|
|
481
|
+
self.field("type", isString, function() { return self.typeName });
|
|
482
482
|
|
|
483
483
|
// Override Dp.buildable for this Def instance.
|
|
484
484
|
Object.defineProperty(self, "buildable", { value: true });
|
|
@@ -570,6 +570,13 @@ function getBuilderName(typeName) {
|
|
|
570
570
|
}
|
|
571
571
|
});
|
|
572
572
|
}
|
|
573
|
+
exports.getBuilderName = getBuilderName;
|
|
574
|
+
|
|
575
|
+
function getStatementBuilderName(typeName) {
|
|
576
|
+
typeName = getBuilderName(typeName);
|
|
577
|
+
return typeName.replace(/(Expression)?$/, "Statement");
|
|
578
|
+
}
|
|
579
|
+
exports.getStatementBuilderName = getStatementBuilderName;
|
|
573
580
|
|
|
574
581
|
// The reason fields are specified using .field(...) instead of an object
|
|
575
582
|
// literal syntax is somewhat subtle: the object literal syntax would
|
|
@@ -678,9 +685,32 @@ Dp.finalize = function() {
|
|
|
678
685
|
|
|
679
686
|
// A linearization of the inheritance hierarchy.
|
|
680
687
|
populateSupertypeList(this.typeName, this.supertypeList);
|
|
688
|
+
|
|
689
|
+
if (this.buildable && this.supertypeList.lastIndexOf("Expression") >= 0) {
|
|
690
|
+
wrapExpressionBuilderWithStatement(this.typeName);
|
|
691
|
+
}
|
|
681
692
|
}
|
|
682
693
|
};
|
|
683
694
|
|
|
695
|
+
// Adds an additional builder for Expression subtypes
|
|
696
|
+
// that wraps the built Expression in an ExpressionStatements.
|
|
697
|
+
function wrapExpressionBuilderWithStatement(typeName) {
|
|
698
|
+
var wrapperName = getStatementBuilderName(typeName);
|
|
699
|
+
|
|
700
|
+
// skip if the builder already exists
|
|
701
|
+
if (builders[wrapperName]) return;
|
|
702
|
+
|
|
703
|
+
// the builder function to wrap with builders.ExpressionStatement
|
|
704
|
+
var wrapped = builders[getBuilderName(typeName)];
|
|
705
|
+
|
|
706
|
+
// skip if there is nothing to wrap
|
|
707
|
+
if (!wrapped) return;
|
|
708
|
+
|
|
709
|
+
builders[wrapperName] = function() {
|
|
710
|
+
return builders.expressionStatement(wrapped.apply(builders, arguments));
|
|
711
|
+
};
|
|
712
|
+
}
|
|
713
|
+
|
|
684
714
|
function populateSupertypeList(typeName, list) {
|
|
685
715
|
list.length = 0;
|
|
686
716
|
list.push(typeName);
|