Starting out the import statement
This commit is contained in:
committed by
Richard van Velzen
parent
6780d0906c
commit
0465bd270d
@@ -702,6 +702,13 @@ var AST_Const = DEFNODE("Const", null, {
|
|||||||
$documentation: "A `const` statement"
|
$documentation: "A `const` statement"
|
||||||
}, AST_Definitions);
|
}, AST_Definitions);
|
||||||
|
|
||||||
|
var AST_Import = DEFNODE("Import", "module_name", {
|
||||||
|
$documentation: "An `import` statement",
|
||||||
|
$propdoc: {
|
||||||
|
module_name: "[AST_String] String literal describing where this module came from",
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
var AST_VarDef = DEFNODE("VarDef", "name value", {
|
var AST_VarDef = DEFNODE("VarDef", "name value", {
|
||||||
$documentation: "A variable declaration; only appears in a AST_Definitions node",
|
$documentation: "A variable declaration; only appears in a AST_Definitions node",
|
||||||
$propdoc: {
|
$propdoc: {
|
||||||
|
|||||||
@@ -1037,6 +1037,12 @@ function OutputStream(options) {
|
|||||||
DEFPRINT(AST_Const, function(self, output){
|
DEFPRINT(AST_Const, function(self, output){
|
||||||
self._do_print(output, "const");
|
self._do_print(output, "const");
|
||||||
});
|
});
|
||||||
|
DEFPRINT(AST_Import, function(self, output) {
|
||||||
|
output.print("import");
|
||||||
|
output.space();
|
||||||
|
self.module_name.print(output);
|
||||||
|
output.semicolon();
|
||||||
|
});
|
||||||
|
|
||||||
function parenthesize_for_noin(node, output, noin) {
|
function parenthesize_for_noin(node, output, noin) {
|
||||||
if (!noin) node.print(output);
|
if (!noin) node.print(output);
|
||||||
|
|||||||
20
lib/parse.js
20
lib/parse.js
@@ -44,9 +44,9 @@
|
|||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var KEYWORDS = 'break case catch class const continue debugger default delete do else extends finally for function if in instanceof new return switch throw try typeof var let void while with';
|
var KEYWORDS = 'break case catch class const continue debugger default delete do else extends finally for function if in instanceof new return switch throw try typeof var let void while with import';
|
||||||
var KEYWORDS_ATOM = 'false null true';
|
var KEYWORDS_ATOM = 'false null true';
|
||||||
var RESERVED_WORDS = 'abstract boolean byte char double enum export final float goto implements import int interface long native package private protected public short static super synchronized this throws transient volatile yield'
|
var RESERVED_WORDS = 'abstract boolean byte char double enum export final float goto implements int interface long native package private protected public short static super synchronized this throws transient volatile yield'
|
||||||
+ " " + KEYWORDS_ATOM + " " + KEYWORDS;
|
+ " " + KEYWORDS_ATOM + " " + KEYWORDS;
|
||||||
var KEYWORDS_BEFORE_EXPRESSION = 'return new delete throw else case';
|
var KEYWORDS_BEFORE_EXPRESSION = 'return new delete throw else case';
|
||||||
|
|
||||||
@@ -909,6 +909,9 @@ function parse($TEXT, options) {
|
|||||||
body : statement()
|
body : statement()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
case "import":
|
||||||
|
return tmp = import_(), semicolon(), tmp;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
unexpected();
|
unexpected();
|
||||||
}
|
}
|
||||||
@@ -1607,6 +1610,19 @@ function parse($TEXT, options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function import_() {
|
||||||
|
return new AST_Import({
|
||||||
|
start: prev(),
|
||||||
|
module_name: new AST_String({
|
||||||
|
start : S.token,
|
||||||
|
value : S.token.value,
|
||||||
|
quote : S.token.quote,
|
||||||
|
end : S.token,
|
||||||
|
}),
|
||||||
|
end: next(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function as_property_name() {
|
function as_property_name() {
|
||||||
var tmp = S.token;
|
var tmp = S.token;
|
||||||
next();
|
next();
|
||||||
|
|||||||
@@ -305,6 +305,14 @@ number_literals: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
import_statement: {
|
||||||
|
input: {
|
||||||
|
import "mod-name";
|
||||||
|
import "module2";
|
||||||
|
}
|
||||||
|
expect_exact: "import\"mod-name\";import\"module2\";"
|
||||||
|
}
|
||||||
|
|
||||||
// Fabio: My patches accidentally caused a crash whenever
|
// Fabio: My patches accidentally caused a crash whenever
|
||||||
// there's an extraneous set of parens around an object.
|
// there's an extraneous set of parens around an object.
|
||||||
regression_cannot_destructure: {
|
regression_cannot_destructure: {
|
||||||
|
|||||||
Reference in New Issue
Block a user