diff --git a/def/babel.js b/def/babel.js index c7839080..608ffbc7 100644 --- a/def/babel.js +++ b/def/babel.js @@ -50,10 +50,6 @@ def("ParenthesizedExpression") .build("expression") .field("expression", def("Expression")); -def("ModuleSpecifier") - .bases("Specifier") - .field("local", def("Identifier")); - def("ImportSpecifier") .bases("ModuleSpecifier") .build("imported", "local") diff --git a/def/es6.js b/def/es6.js index f6ca3145..b73bc07c 100644 --- a/def/es6.js +++ b/def/es6.js @@ -178,10 +178,26 @@ def("ClassImplements") .field("id", def("Identifier")) .field("superClass", or(def("Expression"), null), defaults["null"]); -// Specifier and NamedSpecifier are abstract non-standard types that I +// Specifier and ModuleSpecifier are abstract non-standard types // introduced for definitional convenience. def("Specifier").bases("Node"); +// This supertype is shared/abused by both def/babel.js and +// def/esprima.js. In the future, it will be possible to load only one set +// of definitions appropriate for a given parser, but until then we must +// rely on default functions to reconcile the conflicting AST formats. +def("ModuleSpecifier") + .bases("Specifier") + // This local field is used by Babel/Acorn. It should not technically + // be optional in the Babel/Acorn AST format, but it must be optional + // in the Esprima AST format. + .field("local", or(def("Identifier"), null), defaults["null"]) + // The id and name fields are used by Esprima. The id field should not + // technically be optional in the Esprima AST format, but it must be + // optional in the Babel/Acorn AST format. + .field("id", or(def("Identifier"), null), defaults["null"]) + .field("name", or(def("Identifier"), null), defaults["null"]); + def("TaggedTemplateExpression") .bases("Expression") .build("tag", "quasi") diff --git a/def/esprima.js b/def/esprima.js index c807b251..06113909 100644 --- a/def/esprima.js +++ b/def/esprima.js @@ -32,16 +32,10 @@ def("ObjectPattern") def("SpreadProperty") // Used by Esprima. )]); -def("NamedSpecifier") - .bases("Specifier") - // Note: this abstract type is intentionally not buildable. - .field("id", def("Identifier")) - .field("name", or(def("Identifier"), null), defaults["null"]); - -// Like NamedSpecifier, except type:"ExportSpecifier" and buildable. +// Like ModuleSpecifier, except type:"ExportSpecifier" and buildable. // export {} [from ...]; def("ExportSpecifier") - .bases("NamedSpecifier") + .bases("ModuleSpecifier") .build("id", "name"); // export <*> from ...; @@ -49,10 +43,10 @@ def("ExportBatchSpecifier") .bases("Specifier") .build(); -// Like NamedSpecifier, except type:"ImportSpecifier" and buildable. +// Like ModuleSpecifier, except type:"ImportSpecifier" and buildable. // import {} from ...; def("ImportSpecifier") - .bases("NamedSpecifier") + .bases("ModuleSpecifier") .build("id", "name"); // import <* as id> from ...;