Skip to content

Commit

Permalink
Eliminate NamedSpecifier and make ModuleSpecifier more flexible.
Browse files Browse the repository at this point in the history
This is a temporary workaround for
benjamn/recast#206 until something along the
lines of #57 is implemented.
  • Loading branch information
benjamn committed Aug 7, 2015
1 parent 81d4520 commit a4cd3e9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
4 changes: 0 additions & 4 deletions def/babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
18 changes: 17 additions & 1 deletion def/es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
14 changes: 4 additions & 10 deletions def/esprima.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,21 @@ 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 {<id [as name]>} [from ...];
def("ExportSpecifier")
.bases("NamedSpecifier")
.bases("ModuleSpecifier")
.build("id", "name");

// export <*> from ...;
def("ExportBatchSpecifier")
.bases("Specifier")
.build();

// Like NamedSpecifier, except type:"ImportSpecifier" and buildable.
// Like ModuleSpecifier, except type:"ImportSpecifier" and buildable.
// import {<id [as name]>} from ...;
def("ImportSpecifier")
.bases("NamedSpecifier")
.bases("ModuleSpecifier")
.build("id", "name");

// import <* as id> from ...;
Expand Down

0 comments on commit a4cd3e9

Please sign in to comment.