ast-types 0.15.1 → 0.15.2
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/def/babel-core.js +41 -36
- package/def/core.js +1 -20
- package/def/es-proposals.js +1 -1
- package/fork.d.ts +3 -2
- package/fork.js +2 -2
- package/gen/builders.d.ts +12 -36
- package/gen/namedTypes.d.ts +13 -5
- package/lib/types.d.ts +1 -0
- package/lib/types.js +4 -0
- package/main.d.ts +1 -0
- package/package.json +2 -2
- package/types.d.ts +0 -1
package/def/babel-core.js
CHANGED
|
@@ -5,11 +5,13 @@ var es_proposals_1 = (0, tslib_1.__importDefault)(require("./es-proposals"));
|
|
|
5
5
|
var types_1 = (0, tslib_1.__importDefault)(require("../lib/types"));
|
|
6
6
|
var shared_1 = (0, tslib_1.__importDefault)(require("../lib/shared"));
|
|
7
7
|
function default_1(fork) {
|
|
8
|
+
var _a, _b, _c, _d, _e;
|
|
8
9
|
fork.use(es_proposals_1.default);
|
|
9
10
|
var types = fork.use(types_1.default);
|
|
10
11
|
var defaults = fork.use(shared_1.default).defaults;
|
|
11
12
|
var def = types.Type.def;
|
|
12
13
|
var or = types.Type.or;
|
|
14
|
+
var isUndefined = types.builtInTypes.undefined;
|
|
13
15
|
def("Noop")
|
|
14
16
|
.bases("Statement")
|
|
15
17
|
.build();
|
|
@@ -63,55 +65,49 @@ function default_1(fork) {
|
|
|
63
65
|
.field("body", [def("Statement")])
|
|
64
66
|
.field("directives", [def("Directive")], defaults.emptyArray)
|
|
65
67
|
.field("interpreter", or(def("InterpreterDirective"), null), defaults["null"]);
|
|
68
|
+
function makeLiteralExtra(rawValueType, toRaw) {
|
|
69
|
+
if (rawValueType === void 0) { rawValueType = String; }
|
|
70
|
+
return [
|
|
71
|
+
"extra",
|
|
72
|
+
{
|
|
73
|
+
rawValue: rawValueType,
|
|
74
|
+
raw: String,
|
|
75
|
+
},
|
|
76
|
+
function getDefault() {
|
|
77
|
+
var value = types.getFieldValue(this, "value");
|
|
78
|
+
return {
|
|
79
|
+
rawValue: value,
|
|
80
|
+
raw: toRaw ? toRaw(value) : String(value),
|
|
81
|
+
};
|
|
82
|
+
},
|
|
83
|
+
];
|
|
84
|
+
}
|
|
66
85
|
// Split Literal
|
|
67
|
-
def("StringLiteral")
|
|
86
|
+
(_a = def("StringLiteral")
|
|
68
87
|
.bases("Literal")
|
|
69
88
|
.build("value")
|
|
70
|
-
.field("value", String)
|
|
71
|
-
|
|
89
|
+
.field("value", String))
|
|
90
|
+
.field.apply(_a, makeLiteralExtra(String, function (val) { return JSON.stringify(val); }));
|
|
91
|
+
(_b = def("NumericLiteral")
|
|
72
92
|
.bases("Literal")
|
|
73
93
|
.build("value")
|
|
74
94
|
.field("value", Number)
|
|
75
|
-
.field("raw", or(String, null), defaults["null"])
|
|
76
|
-
.field(
|
|
77
|
-
|
|
78
|
-
raw: String
|
|
79
|
-
}, function getDefault() {
|
|
80
|
-
return {
|
|
81
|
-
rawValue: this.value,
|
|
82
|
-
raw: this.value + ""
|
|
83
|
-
};
|
|
84
|
-
});
|
|
85
|
-
def("BigIntLiteral")
|
|
95
|
+
.field("raw", or(String, null), defaults["null"]))
|
|
96
|
+
.field.apply(_b, makeLiteralExtra(Number));
|
|
97
|
+
(_c = def("BigIntLiteral")
|
|
86
98
|
.bases("Literal")
|
|
87
99
|
.build("value")
|
|
88
100
|
// Only String really seems appropriate here, since BigInt values
|
|
89
101
|
// often exceed the limits of JS numbers.
|
|
90
|
-
.field("value", or(String, Number))
|
|
91
|
-
.field("
|
|
92
|
-
rawValue: String,
|
|
93
|
-
raw: String
|
|
94
|
-
}, function getDefault() {
|
|
95
|
-
return {
|
|
96
|
-
rawValue: String(this.value),
|
|
97
|
-
raw: this.value + "n",
|
|
98
|
-
};
|
|
99
|
-
});
|
|
102
|
+
.field("value", or(String, Number)))
|
|
103
|
+
.field.apply(_c, makeLiteralExtra(String, function (val) { return val + "n"; }));
|
|
100
104
|
// https://github.com/tc39/proposal-decimal
|
|
101
105
|
// https://github.com/babel/babel/pull/11640
|
|
102
|
-
def("DecimalLiteral")
|
|
106
|
+
(_d = def("DecimalLiteral")
|
|
103
107
|
.bases("Literal")
|
|
104
108
|
.build("value")
|
|
105
|
-
.field("value", String)
|
|
106
|
-
.field("
|
|
107
|
-
rawValue: String,
|
|
108
|
-
raw: String
|
|
109
|
-
}, function getDefault() {
|
|
110
|
-
return {
|
|
111
|
-
rawValue: String(this.value),
|
|
112
|
-
raw: this.value + "m",
|
|
113
|
-
};
|
|
114
|
-
});
|
|
109
|
+
.field("value", String))
|
|
110
|
+
.field.apply(_d, makeLiteralExtra(String, function (val) { return val + "m"; }));
|
|
115
111
|
def("NullLiteral")
|
|
116
112
|
.bases("Literal")
|
|
117
113
|
.build()
|
|
@@ -120,13 +116,22 @@ function default_1(fork) {
|
|
|
120
116
|
.bases("Literal")
|
|
121
117
|
.build("value")
|
|
122
118
|
.field("value", Boolean);
|
|
123
|
-
def("RegExpLiteral")
|
|
119
|
+
(_e = def("RegExpLiteral")
|
|
124
120
|
.bases("Literal")
|
|
125
121
|
.build("pattern", "flags")
|
|
126
122
|
.field("pattern", String)
|
|
127
123
|
.field("flags", String)
|
|
128
124
|
.field("value", RegExp, function () {
|
|
129
125
|
return new RegExp(this.pattern, this.flags);
|
|
126
|
+
}))
|
|
127
|
+
.field.apply(_e, makeLiteralExtra(or(RegExp, isUndefined), function (exp) { return "/".concat(exp.pattern, "/").concat(exp.flags || ""); })).field("regex", {
|
|
128
|
+
pattern: String,
|
|
129
|
+
flags: String
|
|
130
|
+
}, function () {
|
|
131
|
+
return {
|
|
132
|
+
pattern: this.pattern,
|
|
133
|
+
flags: this.flags,
|
|
134
|
+
};
|
|
130
135
|
});
|
|
131
136
|
var ObjectExpressionProperty = or(def("Property"), def("ObjectMethod"), def("ObjectProperty"), def("SpreadProperty"), def("SpreadElement"));
|
|
132
137
|
// Split Property -> ObjectProperty and ObjectMethod
|
package/def/core.js
CHANGED
|
@@ -262,26 +262,7 @@ function default_1(fork) {
|
|
|
262
262
|
def("Literal")
|
|
263
263
|
.bases("Expression")
|
|
264
264
|
.build("value")
|
|
265
|
-
.field("value", or(String, Boolean, null, Number, RegExp))
|
|
266
|
-
.field("regex", or({
|
|
267
|
-
pattern: String,
|
|
268
|
-
flags: String
|
|
269
|
-
}, null), function () {
|
|
270
|
-
if (this.value instanceof RegExp) {
|
|
271
|
-
var flags = "";
|
|
272
|
-
if (this.value.ignoreCase)
|
|
273
|
-
flags += "i";
|
|
274
|
-
if (this.value.multiline)
|
|
275
|
-
flags += "m";
|
|
276
|
-
if (this.value.global)
|
|
277
|
-
flags += "g";
|
|
278
|
-
return {
|
|
279
|
-
pattern: this.value.source,
|
|
280
|
-
flags: flags
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
return null;
|
|
284
|
-
});
|
|
265
|
+
.field("value", or(String, Boolean, null, Number, RegExp, BigInt));
|
|
285
266
|
// Abstract (non-buildable) comment supertype. Not a Node.
|
|
286
267
|
def("Comment")
|
|
287
268
|
.bases("Printable")
|
package/def/es-proposals.js
CHANGED
package/fork.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default function (
|
|
1
|
+
import { Plugin } from "./types";
|
|
2
|
+
export default function (plugins: Plugin<any>[]): {
|
|
3
3
|
Type: {
|
|
4
4
|
or(...types: any[]): import("./lib/types").Type<any>;
|
|
5
5
|
from<T>(value: any, name?: string | undefined): import("./lib/types").Type<T>;
|
|
@@ -19,6 +19,7 @@ export default function (defs: Def[]): {
|
|
|
19
19
|
boolean: import("./lib/types").Type<boolean>;
|
|
20
20
|
null: import("./lib/types").Type<null>;
|
|
21
21
|
undefined: import("./lib/types").Type<undefined>;
|
|
22
|
+
BigInt: import("./lib/types").Type<BigInt>;
|
|
22
23
|
};
|
|
23
24
|
namedTypes: import("./gen/namedTypes").NamedTypes;
|
|
24
25
|
builders: import("./gen/builders").builders;
|
package/fork.js
CHANGED
|
@@ -6,10 +6,10 @@ var path_visitor_1 = (0, tslib_1.__importDefault)(require("./lib/path-visitor"))
|
|
|
6
6
|
var equiv_1 = (0, tslib_1.__importDefault)(require("./lib/equiv"));
|
|
7
7
|
var path_1 = (0, tslib_1.__importDefault)(require("./lib/path"));
|
|
8
8
|
var node_path_1 = (0, tslib_1.__importDefault)(require("./lib/node-path"));
|
|
9
|
-
function default_1(
|
|
9
|
+
function default_1(plugins) {
|
|
10
10
|
var fork = createFork();
|
|
11
11
|
var types = fork.use(types_1.default);
|
|
12
|
-
|
|
12
|
+
plugins.forEach(fork.use);
|
|
13
13
|
types.finalize();
|
|
14
14
|
var PathVisitor = fork.use(path_visitor_1.default);
|
|
15
15
|
return {
|
package/gen/builders.d.ts
CHANGED
|
@@ -292,15 +292,11 @@ export interface PropertyBuilder {
|
|
|
292
292
|
}): namedTypes.Property;
|
|
293
293
|
}
|
|
294
294
|
export interface LiteralBuilder {
|
|
295
|
-
(value: string | boolean | null | number | RegExp): namedTypes.Literal;
|
|
295
|
+
(value: string | boolean | null | number | RegExp | BigInt): namedTypes.Literal;
|
|
296
296
|
from(params: {
|
|
297
297
|
comments?: K.CommentKind[] | null;
|
|
298
298
|
loc?: K.SourceLocationKind | null;
|
|
299
|
-
|
|
300
|
-
pattern: string;
|
|
301
|
-
flags: string;
|
|
302
|
-
} | null;
|
|
303
|
-
value: string | boolean | null | number | RegExp;
|
|
299
|
+
value: string | boolean | null | number | RegExp | BigInt;
|
|
304
300
|
}): namedTypes.Literal;
|
|
305
301
|
}
|
|
306
302
|
export interface SequenceExpressionBuilder {
|
|
@@ -911,7 +907,7 @@ export interface TupleExpressionBuilder {
|
|
|
911
907
|
}): namedTypes.TupleExpression;
|
|
912
908
|
}
|
|
913
909
|
export interface ModuleExpressionBuilder {
|
|
914
|
-
(): namedTypes.ModuleExpression;
|
|
910
|
+
(body: K.ProgramKind): namedTypes.ModuleExpression;
|
|
915
911
|
from(params: {
|
|
916
912
|
body: K.ProgramKind;
|
|
917
913
|
comments?: K.CommentKind[] | null;
|
|
@@ -1009,10 +1005,6 @@ export interface JSXTextBuilder {
|
|
|
1009
1005
|
comments?: K.CommentKind[] | null;
|
|
1010
1006
|
loc?: K.SourceLocationKind | null;
|
|
1011
1007
|
raw?: string;
|
|
1012
|
-
regex?: {
|
|
1013
|
-
pattern: string;
|
|
1014
|
-
flags: string;
|
|
1015
|
-
} | null;
|
|
1016
1008
|
value: string;
|
|
1017
1009
|
}): namedTypes.JSXText;
|
|
1018
1010
|
}
|
|
@@ -1812,11 +1804,11 @@ export interface StringLiteralBuilder {
|
|
|
1812
1804
|
(value: string): namedTypes.StringLiteral;
|
|
1813
1805
|
from(params: {
|
|
1814
1806
|
comments?: K.CommentKind[] | null;
|
|
1807
|
+
extra?: {
|
|
1808
|
+
rawValue: string;
|
|
1809
|
+
raw: string;
|
|
1810
|
+
};
|
|
1815
1811
|
loc?: K.SourceLocationKind | null;
|
|
1816
|
-
regex?: {
|
|
1817
|
-
pattern: string;
|
|
1818
|
-
flags: string;
|
|
1819
|
-
} | null;
|
|
1820
1812
|
value: string;
|
|
1821
1813
|
}): namedTypes.StringLiteral;
|
|
1822
1814
|
}
|
|
@@ -1830,10 +1822,6 @@ export interface NumericLiteralBuilder {
|
|
|
1830
1822
|
};
|
|
1831
1823
|
loc?: K.SourceLocationKind | null;
|
|
1832
1824
|
raw?: string | null;
|
|
1833
|
-
regex?: {
|
|
1834
|
-
pattern: string;
|
|
1835
|
-
flags: string;
|
|
1836
|
-
} | null;
|
|
1837
1825
|
value: number;
|
|
1838
1826
|
}): namedTypes.NumericLiteral;
|
|
1839
1827
|
}
|
|
@@ -1846,10 +1834,6 @@ export interface BigIntLiteralBuilder {
|
|
|
1846
1834
|
raw: string;
|
|
1847
1835
|
};
|
|
1848
1836
|
loc?: K.SourceLocationKind | null;
|
|
1849
|
-
regex?: {
|
|
1850
|
-
pattern: string;
|
|
1851
|
-
flags: string;
|
|
1852
|
-
} | null;
|
|
1853
1837
|
value: string | number;
|
|
1854
1838
|
}): namedTypes.BigIntLiteral;
|
|
1855
1839
|
}
|
|
@@ -1862,10 +1846,6 @@ export interface DecimalLiteralBuilder {
|
|
|
1862
1846
|
raw: string;
|
|
1863
1847
|
};
|
|
1864
1848
|
loc?: K.SourceLocationKind | null;
|
|
1865
|
-
regex?: {
|
|
1866
|
-
pattern: string;
|
|
1867
|
-
flags: string;
|
|
1868
|
-
} | null;
|
|
1869
1849
|
value: string;
|
|
1870
1850
|
}): namedTypes.DecimalLiteral;
|
|
1871
1851
|
}
|
|
@@ -1874,10 +1854,6 @@ export interface NullLiteralBuilder {
|
|
|
1874
1854
|
from(params: {
|
|
1875
1855
|
comments?: K.CommentKind[] | null;
|
|
1876
1856
|
loc?: K.SourceLocationKind | null;
|
|
1877
|
-
regex?: {
|
|
1878
|
-
pattern: string;
|
|
1879
|
-
flags: string;
|
|
1880
|
-
} | null;
|
|
1881
1857
|
value?: null;
|
|
1882
1858
|
}): namedTypes.NullLiteral;
|
|
1883
1859
|
}
|
|
@@ -1886,10 +1862,6 @@ export interface BooleanLiteralBuilder {
|
|
|
1886
1862
|
from(params: {
|
|
1887
1863
|
comments?: K.CommentKind[] | null;
|
|
1888
1864
|
loc?: K.SourceLocationKind | null;
|
|
1889
|
-
regex?: {
|
|
1890
|
-
pattern: string;
|
|
1891
|
-
flags: string;
|
|
1892
|
-
} | null;
|
|
1893
1865
|
value: boolean;
|
|
1894
1866
|
}): namedTypes.BooleanLiteral;
|
|
1895
1867
|
}
|
|
@@ -1897,13 +1869,17 @@ export interface RegExpLiteralBuilder {
|
|
|
1897
1869
|
(pattern: string, flags: string): namedTypes.RegExpLiteral;
|
|
1898
1870
|
from(params: {
|
|
1899
1871
|
comments?: K.CommentKind[] | null;
|
|
1872
|
+
extra?: {
|
|
1873
|
+
rawValue: RegExp | undefined;
|
|
1874
|
+
raw: string;
|
|
1875
|
+
};
|
|
1900
1876
|
flags: string;
|
|
1901
1877
|
loc?: K.SourceLocationKind | null;
|
|
1902
1878
|
pattern: string;
|
|
1903
1879
|
regex?: {
|
|
1904
1880
|
pattern: string;
|
|
1905
1881
|
flags: string;
|
|
1906
|
-
}
|
|
1882
|
+
};
|
|
1907
1883
|
value?: RegExp;
|
|
1908
1884
|
}): namedTypes.RegExpLiteral;
|
|
1909
1885
|
}
|
package/gen/namedTypes.d.ts
CHANGED
|
@@ -196,11 +196,7 @@ export declare namespace namedTypes {
|
|
|
196
196
|
}
|
|
197
197
|
interface Literal extends Omit<Expression, "type"> {
|
|
198
198
|
type: "Literal";
|
|
199
|
-
value: string | boolean | null | number | RegExp;
|
|
200
|
-
regex?: {
|
|
201
|
-
pattern: string;
|
|
202
|
-
flags: string;
|
|
203
|
-
} | null;
|
|
199
|
+
value: string | boolean | null | number | RegExp | BigInt;
|
|
204
200
|
}
|
|
205
201
|
interface SequenceExpression extends Omit<Expression, "type"> {
|
|
206
202
|
type: "SequenceExpression";
|
|
@@ -1018,6 +1014,10 @@ export declare namespace namedTypes {
|
|
|
1018
1014
|
interface StringLiteral extends Omit<Literal, "type" | "value"> {
|
|
1019
1015
|
type: "StringLiteral";
|
|
1020
1016
|
value: string;
|
|
1017
|
+
extra?: {
|
|
1018
|
+
rawValue: string;
|
|
1019
|
+
raw: string;
|
|
1020
|
+
};
|
|
1021
1021
|
}
|
|
1022
1022
|
interface NumericLiteral extends Omit<Literal, "type" | "value"> {
|
|
1023
1023
|
type: "NumericLiteral";
|
|
@@ -1057,6 +1057,14 @@ export declare namespace namedTypes {
|
|
|
1057
1057
|
pattern: string;
|
|
1058
1058
|
flags: string;
|
|
1059
1059
|
value?: RegExp;
|
|
1060
|
+
extra?: {
|
|
1061
|
+
rawValue: RegExp | undefined;
|
|
1062
|
+
raw: string;
|
|
1063
|
+
};
|
|
1064
|
+
regex?: {
|
|
1065
|
+
pattern: string;
|
|
1066
|
+
flags: string;
|
|
1067
|
+
};
|
|
1060
1068
|
}
|
|
1061
1069
|
interface ClassMethod extends Omit<Declaration, "type">, Omit<Function, "type" | "body"> {
|
|
1062
1070
|
type: "ClassMethod";
|
package/lib/types.d.ts
CHANGED
|
@@ -118,6 +118,7 @@ export default function typesPlugin(_fork: Fork): {
|
|
|
118
118
|
boolean: Type<boolean>;
|
|
119
119
|
null: Type<null>;
|
|
120
120
|
undefined: Type<undefined>;
|
|
121
|
+
BigInt: Type<BigInt>;
|
|
121
122
|
};
|
|
122
123
|
getSupertypeNames: (typeName: string) => string[];
|
|
123
124
|
computeSupertypeLookupTable: (candidates: any) => {
|
package/lib/types.js
CHANGED
|
@@ -316,6 +316,9 @@ function typesPlugin(_fork) {
|
|
|
316
316
|
var isBoolean = defBuiltInType("boolean", true);
|
|
317
317
|
var isNull = defBuiltInType("null", null);
|
|
318
318
|
var isUndefined = defBuiltInType("undefined", undefined);
|
|
319
|
+
var isBigInt = typeof BigInt === "function"
|
|
320
|
+
? defBuiltInType("BigInt", BigInt(1234))
|
|
321
|
+
: new PredicateType("BigInt", function () { return false; });
|
|
319
322
|
var builtInTypes = {
|
|
320
323
|
string: isString,
|
|
321
324
|
function: isFunction,
|
|
@@ -327,6 +330,7 @@ function typesPlugin(_fork) {
|
|
|
327
330
|
boolean: isBoolean,
|
|
328
331
|
null: isNull,
|
|
329
332
|
undefined: isUndefined,
|
|
333
|
+
BigInt: isBigInt,
|
|
330
334
|
};
|
|
331
335
|
// In order to return the same Def instance every time Type.def is called
|
|
332
336
|
// with a particular name, those instances need to be stored in a cache.
|
package/main.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ declare const astNodesAreEquivalent: {
|
|
|
19
19
|
boolean: Type<boolean>;
|
|
20
20
|
null: Type<null>;
|
|
21
21
|
undefined: Type<undefined>;
|
|
22
|
+
BigInt: Type<BigInt>;
|
|
22
23
|
}, defineMethod: (name: any, func?: Function | undefined) => Function, eachField: (object: any, callback: (name: any, value: any) => any, context?: any) => void, finalize: () => void, getBuilderName: (typeName: any) => any, getFieldNames: (object: any) => string[], getFieldValue: (object: any, fieldName: any) => any, getSupertypeNames: (typeName: string) => string[], NodePath: import("./lib/node-path").NodePathConstructor, Path: import("./lib/path").PathConstructor, PathVisitor: import("./lib/path-visitor").PathVisitorConstructor, someField: (object: any, callback: (name: any, value: any) => any, context?: any) => boolean, Type: {
|
|
23
24
|
or(...types: any[]): Type<any>;
|
|
24
25
|
from<T>(value: any, name?: string | undefined): Type<T>;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "Ben Newman <bn@cs.stanford.edu>",
|
|
3
3
|
"name": "ast-types",
|
|
4
|
-
"version": "0.15.
|
|
4
|
+
"version": "0.15.2",
|
|
5
5
|
"description": "Esprima-compatible implementation of the Mozilla JS Parser API",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"ast",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"espree": "9.1.0",
|
|
50
50
|
"esprima": "4.0.1",
|
|
51
51
|
"esprima-fb": "15001.1001.0-dev-harmony-fb",
|
|
52
|
-
"flow-parser": "0.
|
|
52
|
+
"flow-parser": "0.166.0",
|
|
53
53
|
"glob": "7.2.0",
|
|
54
54
|
"mocha": "^9.1.3",
|
|
55
55
|
"recast": "0.20.5",
|