8149929: Nashorn Parser API needs to be updated for ES6
Reviewed-by: mhaupt, hannesw
This commit is contained in:
parent
d50a21bbb3
commit
4597649209
@ -35,7 +35,9 @@ build.compiler=modern
|
||||
javac.source=1.9
|
||||
javac.target=1.9
|
||||
|
||||
javadoc.option=-tag "implSpec:a:Implementation Requirements:"
|
||||
javadoc.option=\
|
||||
-tag "implSpec:a:Implementation Requirements:"\
|
||||
-tag "implNote:a:Implementation Note:"
|
||||
|
||||
# nashorn version information
|
||||
nashorn.version=0.1
|
||||
|
@ -209,7 +209,7 @@ function prettyPrint(file) {
|
||||
}
|
||||
print("function ");
|
||||
if (func.name) {
|
||||
print(func.name);
|
||||
print(func.name.name);
|
||||
}
|
||||
printFunctionBody(func, extra, end);
|
||||
if (funcDecl) {
|
||||
@ -608,7 +608,7 @@ function prettyPrint(file) {
|
||||
|
||||
visitVariable: function(node, extra) {
|
||||
indent();
|
||||
print("var " + node.name);
|
||||
print("var " + node.binding.name);
|
||||
var init = node.initializer;
|
||||
if (init) {
|
||||
print(" = ");
|
||||
|
@ -439,6 +439,10 @@ final class NashornCompleter implements Completer {
|
||||
args.add("-strict");
|
||||
}
|
||||
|
||||
if (env._es6) {
|
||||
args.add("--language=es6");
|
||||
}
|
||||
|
||||
return Parser.create(args.toArray(new String[0]));
|
||||
}
|
||||
}
|
||||
|
@ -38,11 +38,11 @@ package jdk.nashorn.api.tree;
|
||||
*/
|
||||
public interface CatchTree extends Tree {
|
||||
/**
|
||||
* Returns the catch parameter identifier of the exception caught.
|
||||
* Returns the catch parameter identifier or parameter binding pattern of the exception caught.
|
||||
*
|
||||
* @return the catch parameter identifier
|
||||
* @return the catch parameter identifier or parameter binding pattern
|
||||
*/
|
||||
IdentifierTree getParameter();
|
||||
ExpressionTree getParameter();
|
||||
|
||||
/**
|
||||
* Returns the code block of this catch block.
|
||||
|
@ -28,12 +28,12 @@ package jdk.nashorn.api.tree;
|
||||
import jdk.nashorn.internal.ir.CatchNode;
|
||||
|
||||
final class CatchTreeImpl extends TreeImpl implements CatchTree {
|
||||
private final IdentifierTree param;
|
||||
private final ExpressionTree param;
|
||||
private final BlockTree block;
|
||||
private final ExpressionTree condition;
|
||||
|
||||
CatchTreeImpl(final CatchNode node,
|
||||
final IdentifierTree param,
|
||||
final ExpressionTree param,
|
||||
final BlockTree block,
|
||||
final ExpressionTree condition) {
|
||||
super(node);
|
||||
@ -48,7 +48,7 @@ final class CatchTreeImpl extends TreeImpl implements CatchTree {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentifierTree getParameter() {
|
||||
public ExpressionTree getParameter() {
|
||||
return param;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A tree node that represents a <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-class-definitions">class declaration</a>.
|
||||
*
|
||||
* @since 9
|
||||
*/
|
||||
public interface ClassDeclarationTree extends StatementTree {
|
||||
|
||||
/**
|
||||
* Class identifier.
|
||||
*
|
||||
* @return the class identifier
|
||||
*/
|
||||
IdentifierTree getName();
|
||||
|
||||
/**
|
||||
* The expression of the {@code extends} clause. Optional.
|
||||
*
|
||||
* @return the class heritage
|
||||
*/
|
||||
ExpressionTree getClassHeritage();
|
||||
|
||||
/**
|
||||
* Get the constructor method definition.
|
||||
*
|
||||
* @return the constructor
|
||||
*/
|
||||
PropertyTree getConstructor();
|
||||
|
||||
/**
|
||||
* Get other property definitions except for the constructor.
|
||||
*
|
||||
* @return the class elements
|
||||
*/
|
||||
List<? extends PropertyTree> getClassElements();
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import java.util.List;
|
||||
import jdk.nashorn.internal.ir.VarNode;
|
||||
|
||||
final class ClassDeclarationTreeImpl extends StatementTreeImpl implements ClassDeclarationTree {
|
||||
|
||||
private final IdentifierTree name;
|
||||
private final ExpressionTree classHeritage;
|
||||
private final PropertyTree constructor;
|
||||
private final List<? extends PropertyTree> classElements;
|
||||
|
||||
ClassDeclarationTreeImpl(final VarNode node, final IdentifierTree name,
|
||||
final ExpressionTree classHeritage, final PropertyTree constructor,
|
||||
final List<? extends PropertyTree> classElements) {
|
||||
super(node);
|
||||
this.name = name;
|
||||
this.classHeritage = classHeritage;
|
||||
this.constructor = constructor;
|
||||
this.classElements = classElements;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tree.Kind getKind() {
|
||||
return Tree.Kind.CLASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentifierTree getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionTree getClassHeritage() {
|
||||
return classHeritage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PropertyTree getConstructor() {
|
||||
return constructor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends PropertyTree> getClassElements() {
|
||||
return classElements;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(final TreeVisitor<R,D> visitor, final D data) {
|
||||
return visitor.visitClassDeclaration(this, data);
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A tree node that represents a <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-class-definitions">class expression</a>.
|
||||
*
|
||||
* @since 9
|
||||
*/
|
||||
public interface ClassExpressionTree extends ExpressionTree {
|
||||
/**
|
||||
* Class identifier. Optional.
|
||||
*
|
||||
* @return the class identifier
|
||||
*/
|
||||
IdentifierTree getName();
|
||||
|
||||
/**
|
||||
* The expression of the {@code extends} clause. Optional.
|
||||
*
|
||||
* @return the class heritage
|
||||
*/
|
||||
ExpressionTree getClassHeritage();
|
||||
|
||||
/**
|
||||
* Get the constructor method definition.
|
||||
*
|
||||
* @return the constructor
|
||||
*/
|
||||
PropertyTree getConstructor();
|
||||
|
||||
/**
|
||||
* Get other property definitions except for the constructor.
|
||||
*
|
||||
* @return the class elements
|
||||
*/
|
||||
List<? extends PropertyTree> getClassElements();
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import java.util.List;
|
||||
import jdk.nashorn.internal.ir.ClassNode;
|
||||
|
||||
final class ClassExpressionTreeImpl extends ExpressionTreeImpl implements ClassExpressionTree {
|
||||
|
||||
private final IdentifierTree name;
|
||||
private final ExpressionTree classHeritage;
|
||||
private final PropertyTree constructor;
|
||||
private final List<? extends PropertyTree> classElements;
|
||||
|
||||
ClassExpressionTreeImpl(final ClassNode cn, final IdentifierTree name,
|
||||
final ExpressionTree classHeritage, final PropertyTree constructor,
|
||||
final List<? extends PropertyTree> classElements) {
|
||||
super(cn);
|
||||
this.name = name;
|
||||
this.classHeritage = classHeritage;
|
||||
this.constructor = constructor;
|
||||
this.classElements = classElements;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.CLASS_EXPRESSION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentifierTree getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionTree getClassHeritage() {
|
||||
return classHeritage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PropertyTree getConstructor() {
|
||||
return constructor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends PropertyTree> getClassElements() {
|
||||
return classElements;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(final TreeVisitor<R,D> visitor, final D data) {
|
||||
return visitor.visitClassExpression(this, data);
|
||||
}
|
||||
}
|
@ -62,4 +62,12 @@ public interface CompilationUnitTree extends Tree {
|
||||
* @return the line map for this compilation unit
|
||||
*/
|
||||
LineMap getLineMap();
|
||||
|
||||
/**
|
||||
* Return the {@link ModuleTree} associated with this compilation unit. This is null,
|
||||
* if there is no module information from this compilation unit.
|
||||
*
|
||||
* @return the Module info or null
|
||||
*/
|
||||
ModuleTree getModule();
|
||||
}
|
||||
|
@ -32,13 +32,18 @@ final class CompilationUnitTreeImpl extends TreeImpl
|
||||
implements CompilationUnitTree {
|
||||
private final FunctionNode funcNode;
|
||||
private final List<? extends Tree> elements;
|
||||
private final ModuleTree module;
|
||||
|
||||
CompilationUnitTreeImpl(final FunctionNode node,
|
||||
final List<? extends Tree> elements) {
|
||||
final List<? extends Tree> elements,
|
||||
final ModuleTree module) {
|
||||
super(node);
|
||||
this.funcNode = node;
|
||||
assert funcNode.getKind() == FunctionNode.Kind.SCRIPT : "script function expected";
|
||||
assert funcNode.getKind() == FunctionNode.Kind.SCRIPT ||
|
||||
funcNode.getKind() == FunctionNode.Kind.MODULE :
|
||||
"script or module function expected";
|
||||
this.elements = elements;
|
||||
this.module = module;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -66,6 +71,11 @@ final class CompilationUnitTreeImpl extends TreeImpl
|
||||
return new LineMapImpl(funcNode.getSource());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModuleTree getModule() {
|
||||
return module;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(final TreeVisitor<R,D> visitor, final D data) {
|
||||
return visitor.visitCompilationUnit(this, data);
|
||||
|
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import jdk.nashorn.internal.ir.ExpressionStatement;
|
||||
import jdk.nashorn.internal.parser.TokenType;
|
||||
|
||||
// This implementation of VariableTree represents a destructuring declaration
|
||||
final class DestructuringDeclTreeImpl extends StatementTreeImpl
|
||||
implements VariableTree {
|
||||
|
||||
private final TokenType declType;
|
||||
private final ExpressionTree lhs;
|
||||
private final ExpressionTree init;
|
||||
|
||||
DestructuringDeclTreeImpl(ExpressionStatement exprStat, final ExpressionTree lhs, final ExpressionTree init) {
|
||||
super(exprStat);
|
||||
assert exprStat.destructuringDeclarationType() != null : "expecting a destructuring decl. statement";
|
||||
|
||||
this.declType = exprStat.destructuringDeclarationType();
|
||||
this.lhs = lhs;
|
||||
this.init = init;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.VARIABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionTree getBinding() {
|
||||
return lhs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionTree getInitializer() {
|
||||
return init;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConst() {
|
||||
return declType == TokenType.CONST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLet() {
|
||||
return declType == TokenType.LET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(final TreeVisitor<R,D> visitor, final D data) {
|
||||
return visitor.visitVariable(this, data);
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A Tree node for export entry in <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-modules">Module information</a>.
|
||||
*/
|
||||
public interface ExportEntryTree extends Tree {
|
||||
/**
|
||||
* Returns the entry's export name.
|
||||
*
|
||||
* @return the export name
|
||||
*/
|
||||
public IdentifierTree getExportName();
|
||||
|
||||
/**
|
||||
* Returns the entry's module request.
|
||||
*
|
||||
* @return the module request
|
||||
*/
|
||||
public IdentifierTree getModuleRequest();
|
||||
|
||||
/**
|
||||
* Returns the entry's import name.
|
||||
*
|
||||
* @return the import name
|
||||
*/
|
||||
public IdentifierTree getImportName();
|
||||
|
||||
/**
|
||||
* Returns the entry's local name.
|
||||
*
|
||||
* @return the local name
|
||||
*/
|
||||
public IdentifierTree getLocalName();
|
||||
}
|
@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import jdk.nashorn.internal.ir.FunctionNode;
|
||||
import jdk.nashorn.internal.ir.IdentNode;
|
||||
import jdk.nashorn.internal.ir.Module;
|
||||
import static jdk.nashorn.api.tree.ModuleTreeImpl.identOrNull;
|
||||
|
||||
final class ExportEntryTreeImpl extends TreeImpl implements ExportEntryTree {
|
||||
private final long startPos, endPos;
|
||||
private final IdentifierTree exportName;
|
||||
private final IdentifierTree moduleRequest;
|
||||
private final IdentifierTree importName;
|
||||
private final IdentifierTree localName;
|
||||
|
||||
private ExportEntryTreeImpl(final long startPos, final long endPos,
|
||||
IdentifierTree exportName,
|
||||
IdentifierTree moduleRequest,
|
||||
IdentifierTree importName,
|
||||
IdentifierTree localName) {
|
||||
super(null); // no underlying Node!
|
||||
this.startPos = startPos;
|
||||
this.endPos = endPos;
|
||||
this.exportName = exportName;
|
||||
this.moduleRequest = moduleRequest;
|
||||
this.importName = importName;
|
||||
this.localName = localName;
|
||||
}
|
||||
|
||||
private static ExportEntryTreeImpl createExportEntry(Module.ExportEntry entry) {
|
||||
return new ExportEntryTreeImpl(entry.getStartPosition(),
|
||||
entry.getEndPosition(),
|
||||
identOrNull(entry.getExportName()),
|
||||
identOrNull(entry.getModuleRequest()),
|
||||
identOrNull(entry.getImportName()),
|
||||
identOrNull(entry.getLocalName()));
|
||||
}
|
||||
|
||||
static List<ExportEntryTreeImpl> createExportList(List<Module.ExportEntry> exportList) {
|
||||
return exportList.stream().
|
||||
map(ExportEntryTreeImpl::createExportEntry).
|
||||
collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Tree.Kind.EXPORT_ENTRY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(final TreeVisitor<R,D> visitor, final D data) {
|
||||
return visitor.visitExportEntry(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getStartPosition() {
|
||||
return startPos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getEndPosition() {
|
||||
return endPos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentifierTree getExportName() {
|
||||
return exportName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentifierTree getModuleRequest() {
|
||||
return moduleRequest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentifierTree getImportName() {
|
||||
return importName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentifierTree getLocalName() {
|
||||
return localName;
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
/**
|
||||
* A tree node for <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-for-in-and-for-of-statements">for..of statement</a>.
|
||||
*
|
||||
* For example:
|
||||
* <pre>
|
||||
* for ( <em>variable</em> of <em>expression</em> )
|
||||
* <em>statement</em>
|
||||
* </pre>
|
||||
*
|
||||
* @since 9
|
||||
*/
|
||||
public interface ForOfLoopTree extends LoopTree {
|
||||
/**
|
||||
* The for..in left hand side expression.
|
||||
*
|
||||
* @return the left hand side expression
|
||||
*/
|
||||
ExpressionTree getVariable();
|
||||
|
||||
/**
|
||||
* The object or array being whose properties are iterated.
|
||||
*
|
||||
* @return the object or array expression being iterated
|
||||
*/
|
||||
ExpressionTree getExpression();
|
||||
|
||||
/**
|
||||
* The statement contained in this for..in statement.
|
||||
*
|
||||
* @return the statement
|
||||
*/
|
||||
@Override
|
||||
StatementTree getStatement();
|
||||
}
|
||||
|
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import jdk.nashorn.internal.ir.ForNode;
|
||||
|
||||
final class ForOfLoopTreeImpl extends StatementTreeImpl implements ForOfLoopTree {
|
||||
private final ExpressionTree lhsExpr;
|
||||
private final ExpressionTree expr;
|
||||
private final StatementTree stat;
|
||||
|
||||
ForOfLoopTreeImpl(final ForNode node,
|
||||
final ExpressionTree lhsExpr,
|
||||
final ExpressionTree expr,
|
||||
final StatementTree stat) {
|
||||
super(node);
|
||||
assert node.isForIn() : "for ..in expected";
|
||||
this.lhsExpr = lhsExpr;
|
||||
this.expr = expr;
|
||||
this.stat = stat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.FOR_IN_LOOP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionTree getVariable() {
|
||||
return lhsExpr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionTree getExpression() {
|
||||
return expr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StatementTree getStatement() {
|
||||
return stat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(final TreeVisitor<R,D> visitor, final D data) {
|
||||
return visitor.visitForOfLoop(this, data);
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -28,7 +28,7 @@ package jdk.nashorn.api.tree;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A tree node for a function declaration.
|
||||
* A tree node for a <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-function-definitions">function declaration</a>.
|
||||
*
|
||||
* For example:
|
||||
* <pre>
|
||||
@ -37,6 +37,12 @@ import java.util.List;
|
||||
* <em>body</em>
|
||||
* </pre>
|
||||
*
|
||||
* <pre>
|
||||
* <em>function*</em> <em>name</em>
|
||||
* ( <em>parameters</em> )
|
||||
* <em>body</em>
|
||||
* </pre>
|
||||
*
|
||||
* @since 9
|
||||
*/
|
||||
public interface FunctionDeclarationTree extends StatementTree {
|
||||
@ -45,7 +51,7 @@ public interface FunctionDeclarationTree extends StatementTree {
|
||||
*
|
||||
* @return name the function declared
|
||||
*/
|
||||
String getName();
|
||||
IdentifierTree getName();
|
||||
|
||||
/**
|
||||
* Returns the parameters of this function.
|
||||
@ -67,4 +73,11 @@ public interface FunctionDeclarationTree extends StatementTree {
|
||||
* @return true if this function is strict
|
||||
*/
|
||||
boolean isStrict();
|
||||
|
||||
/**
|
||||
* Is this a generator function?
|
||||
*
|
||||
* @return true if this is a generator function
|
||||
*/
|
||||
boolean isGenerator();
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -32,7 +32,7 @@ import jdk.nashorn.internal.ir.VarNode;
|
||||
final class FunctionDeclarationTreeImpl extends StatementTreeImpl
|
||||
implements FunctionDeclarationTree {
|
||||
private final FunctionNode funcNode;
|
||||
private final String funcName;
|
||||
private final IdentifierTree funcName;
|
||||
private final List<? extends ExpressionTree> params;
|
||||
private final BlockTree body;
|
||||
|
||||
@ -43,7 +43,7 @@ final class FunctionDeclarationTreeImpl extends StatementTreeImpl
|
||||
assert node.getInit() instanceof FunctionNode : "function expected";
|
||||
funcNode = (FunctionNode)node.getInit();
|
||||
assert funcNode.isDeclared() : "function declaration expected";
|
||||
funcName = funcNode.isAnonymous()? null : node.getName().getName();
|
||||
funcName = funcNode.isAnonymous()? null : new IdentifierTreeImpl(node.getName());
|
||||
this.params = params;
|
||||
this.body = body;
|
||||
}
|
||||
@ -54,7 +54,7 @@ final class FunctionDeclarationTreeImpl extends StatementTreeImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
public IdentifierTree getName() {
|
||||
return funcName;
|
||||
}
|
||||
|
||||
@ -73,6 +73,11 @@ final class FunctionDeclarationTreeImpl extends StatementTreeImpl
|
||||
return funcNode.isStrict();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGenerator() {
|
||||
return funcNode.getKind() == FunctionNode.Kind.GENERATOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(final TreeVisitor<R,D> visitor, final D data) {
|
||||
return visitor.visitFunctionDeclaration(this, data);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -28,7 +28,7 @@ package jdk.nashorn.api.tree;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A tree node for a function expression.
|
||||
* A tree node for <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-function-defining-expressions">function expressions</a> including <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-arrow-function-definitions">arrow functions</a>.
|
||||
*
|
||||
* For example:
|
||||
* <pre>
|
||||
@ -37,6 +37,10 @@ import java.util.List;
|
||||
* <em>body</em>
|
||||
* </pre>
|
||||
*
|
||||
* <pre>
|
||||
* <em>var</em> func = <em>(x) => x+1</em>
|
||||
* </pre>
|
||||
*
|
||||
* @since 9
|
||||
*/
|
||||
public interface FunctionExpressionTree extends ExpressionTree {
|
||||
@ -45,7 +49,7 @@ public interface FunctionExpressionTree extends ExpressionTree {
|
||||
*
|
||||
* @return name the function declared
|
||||
*/
|
||||
String getName();
|
||||
IdentifierTree getName();
|
||||
|
||||
/**
|
||||
* Returns the parameters of this function.
|
||||
@ -55,11 +59,13 @@ public interface FunctionExpressionTree extends ExpressionTree {
|
||||
List<? extends ExpressionTree> getParameters();
|
||||
|
||||
/**
|
||||
* Returns the body of code of this function.
|
||||
* Returns the body of this function. This may be a {@link BlockTree} when this
|
||||
* function has a block body. This is an {@link ExpressionTree} when the function body
|
||||
* is a concise expression as in an expression arrow, or in an expression closure.
|
||||
*
|
||||
* @return the body of code
|
||||
* @return the body of this function
|
||||
*/
|
||||
BlockTree getBody();
|
||||
Tree getBody();
|
||||
|
||||
/**
|
||||
* Is this a strict function?
|
||||
@ -67,4 +73,18 @@ public interface FunctionExpressionTree extends ExpressionTree {
|
||||
* @return true if this function is strict
|
||||
*/
|
||||
boolean isStrict();
|
||||
|
||||
/**
|
||||
* Is this a arrow function?
|
||||
*
|
||||
* @return true if this is a arrow function
|
||||
*/
|
||||
boolean isArrow();
|
||||
|
||||
/**
|
||||
* Is this a generator function?
|
||||
*
|
||||
* @return true if this is a generator function
|
||||
*/
|
||||
boolean isGenerator();
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -31,9 +31,9 @@ import jdk.nashorn.internal.ir.FunctionNode;
|
||||
final class FunctionExpressionTreeImpl extends ExpressionTreeImpl
|
||||
implements FunctionExpressionTree {
|
||||
private final FunctionNode funcNode;
|
||||
private final String funcName;
|
||||
private final IdentifierTree funcName;
|
||||
private final List<? extends ExpressionTree> params;
|
||||
private final BlockTree body;
|
||||
private final Tree body;
|
||||
|
||||
FunctionExpressionTreeImpl(final FunctionNode node,
|
||||
final List<? extends ExpressionTree> params,
|
||||
@ -46,11 +46,17 @@ final class FunctionExpressionTreeImpl extends ExpressionTreeImpl
|
||||
if (node.isAnonymous() || kind == FunctionNode.Kind.GETTER || kind == FunctionNode.Kind.SETTER) {
|
||||
funcName = null;
|
||||
} else {
|
||||
funcName = node.getIdent().getName();
|
||||
funcName = new IdentifierTreeImpl(node.getIdent());
|
||||
}
|
||||
|
||||
this.params = params;
|
||||
this.body = body;
|
||||
if (node.getFlag(FunctionNode.HAS_EXPRESSION_BODY)) {
|
||||
StatementTree first = body.getStatements().get(0);
|
||||
assert first instanceof ReturnTree : "consise func. expression should have a return statement";
|
||||
this.body = ((ReturnTree)first).getExpression();
|
||||
} else {
|
||||
this.body = body;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -59,7 +65,7 @@ final class FunctionExpressionTreeImpl extends ExpressionTreeImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
public IdentifierTree getName() {
|
||||
return funcName;
|
||||
}
|
||||
|
||||
@ -69,7 +75,7 @@ final class FunctionExpressionTreeImpl extends ExpressionTreeImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockTree getBody() {
|
||||
public Tree getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
@ -78,6 +84,16 @@ final class FunctionExpressionTreeImpl extends ExpressionTreeImpl
|
||||
return funcNode.isStrict();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isArrow() {
|
||||
return funcNode.getKind() == FunctionNode.Kind.ARROW;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGenerator() {
|
||||
return funcNode.getKind() == FunctionNode.Kind.GENERATOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(final TreeVisitor<R,D> visitor, final D data) {
|
||||
return visitor.visitFunctionExpression(this, data);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -27,6 +27,7 @@ package jdk.nashorn.api.tree;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import jdk.nashorn.internal.ir.AccessNode;
|
||||
import jdk.nashorn.internal.ir.BinaryNode;
|
||||
import jdk.nashorn.internal.ir.Block;
|
||||
@ -35,6 +36,7 @@ import jdk.nashorn.internal.ir.BreakNode;
|
||||
import jdk.nashorn.internal.ir.CallNode;
|
||||
import jdk.nashorn.internal.ir.CaseNode;
|
||||
import jdk.nashorn.internal.ir.CatchNode;
|
||||
import jdk.nashorn.internal.ir.ClassNode;
|
||||
import jdk.nashorn.internal.ir.ContinueNode;
|
||||
import jdk.nashorn.internal.ir.DebuggerNode;
|
||||
import jdk.nashorn.internal.ir.EmptyNode;
|
||||
@ -56,6 +58,7 @@ import jdk.nashorn.internal.ir.RuntimeNode;
|
||||
import jdk.nashorn.internal.ir.SplitNode;
|
||||
import jdk.nashorn.internal.ir.Statement;
|
||||
import jdk.nashorn.internal.ir.SwitchNode;
|
||||
import jdk.nashorn.internal.ir.TemplateLiteral;
|
||||
import jdk.nashorn.internal.ir.TernaryNode;
|
||||
import jdk.nashorn.internal.ir.ThrowNode;
|
||||
import jdk.nashorn.internal.ir.TryNode;
|
||||
@ -87,11 +90,14 @@ final class IRTranslator extends SimpleNodeVisitor {
|
||||
return null;
|
||||
}
|
||||
|
||||
assert (node.getKind() == FunctionNode.Kind.SCRIPT) : "script function expected";
|
||||
assert node.getKind() == FunctionNode.Kind.SCRIPT ||
|
||||
node.getKind() == FunctionNode.Kind.MODULE :
|
||||
"script or module function expected";
|
||||
|
||||
final Block body = node.getBody();
|
||||
return new CompilationUnitTreeImpl(node,
|
||||
translateStats(body != null? getOrderedStatements(body.getStatements()) : null));
|
||||
translateStats(body != null? getOrderedStatements(body.getStatements()) : null),
|
||||
translateModule(node));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -184,8 +190,15 @@ final class IRTranslator extends SimpleNodeVisitor {
|
||||
|
||||
@Override
|
||||
public boolean enterExpressionStatement(final ExpressionStatement expressionStatement) {
|
||||
curStat = new ExpressionStatementTreeImpl(expressionStatement,
|
||||
if (expressionStatement.destructuringDeclarationType() != null) {
|
||||
ExpressionTree expr = translateExpr(expressionStatement.getExpression());
|
||||
assert expr instanceof AssignmentTree : "destructuring decl. statement does not have assignment";
|
||||
AssignmentTree assign = (AssignmentTree)expr;
|
||||
curStat = new DestructuringDeclTreeImpl(expressionStatement, assign.getVariable(), assign.getExpression());
|
||||
} else {
|
||||
curStat = new ExpressionStatementTreeImpl(expressionStatement,
|
||||
translateExpr(expressionStatement.getExpression()));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -209,6 +222,11 @@ final class IRTranslator extends SimpleNodeVisitor {
|
||||
translateExpr(forNode.getInit()),
|
||||
translateExpr(forNode.getModify()),
|
||||
translateBlock(forNode.getBody()));
|
||||
} else if (forNode.isForOf()) {
|
||||
curStat = new ForOfLoopTreeImpl(forNode,
|
||||
translateExpr(forNode.getInit()),
|
||||
translateExpr(forNode.getModify()),
|
||||
translateBlock(forNode.getBody()));
|
||||
} else {
|
||||
curStat = new ForLoopTreeImpl(forNode,
|
||||
translateExpr(forNode.getInit()),
|
||||
@ -224,8 +242,7 @@ final class IRTranslator extends SimpleNodeVisitor {
|
||||
public boolean enterFunctionNode(final FunctionNode functionNode) {
|
||||
assert !functionNode.isDeclared() || functionNode.isAnonymous() : "should not reach here for function declaration";
|
||||
|
||||
final List<? extends ExpressionTree> paramTrees
|
||||
= translateExprs(functionNode.getParameters());
|
||||
final List<? extends ExpressionTree> paramTrees = translateParameters(functionNode);
|
||||
final BlockTree blockTree = (BlockTree) translateBlock(functionNode.getBody(), true);
|
||||
curExpr = new FunctionExpressionTreeImpl(functionNode, paramTrees, blockTree);
|
||||
|
||||
@ -291,14 +308,7 @@ final class IRTranslator extends SimpleNodeVisitor {
|
||||
@Override
|
||||
public boolean enterObjectNode(final ObjectNode objectNode) {
|
||||
final List<PropertyNode> propNodes = objectNode.getElements();
|
||||
final List<PropertyTreeImpl> propTrees = new ArrayList<>(propNodes.size());
|
||||
for (final PropertyNode propNode : propNodes) {
|
||||
propTrees.add(new PropertyTreeImpl(propNode,
|
||||
translateExpr(propNode.getKey()),
|
||||
translateExpr(propNode.getValue()),
|
||||
(FunctionExpressionTree) translateExpr(propNode.getGetter()),
|
||||
(FunctionExpressionTree) translateExpr(propNode.getSetter())));
|
||||
}
|
||||
final List<? extends PropertyTree> propTrees = translateProperties(propNodes);
|
||||
curExpr = new ObjectLiteralTreeImpl(objectNode, propTrees);
|
||||
return false;
|
||||
}
|
||||
@ -346,6 +356,12 @@ final class IRTranslator extends SimpleNodeVisitor {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enterTemplateLiteral(final TemplateLiteral templateLiteral) {
|
||||
curExpr = new TemplateLiteralTreeImpl(templateLiteral, translateExprs(templateLiteral.getExpressions()));
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enterTernaryNode(final TernaryNode ternaryNode) {
|
||||
curExpr = new ConditionalExpressionTreeImpl(ternaryNode,
|
||||
@ -386,6 +402,14 @@ final class IRTranslator extends SimpleNodeVisitor {
|
||||
if (unaryNode.isTokenType(TokenType.NEW)) {
|
||||
curExpr = new NewTreeImpl(unaryNode,
|
||||
translateExpr(unaryNode.getExpression()));
|
||||
} else if (unaryNode.isTokenType(TokenType.YIELD) ||
|
||||
unaryNode.isTokenType(TokenType.YIELD_STAR)) {
|
||||
curExpr = new YieldTreeImpl(unaryNode,
|
||||
translateExpr(unaryNode.getExpression()));
|
||||
} else if (unaryNode.isTokenType(TokenType.SPREAD_ARGUMENT) ||
|
||||
unaryNode.isTokenType(TokenType.SPREAD_ARRAY)) {
|
||||
curExpr = new SpreadTreeImpl(unaryNode,
|
||||
translateExpr(unaryNode.getExpression()));
|
||||
} else {
|
||||
curExpr = new UnaryTreeImpl(unaryNode,
|
||||
translateExpr(unaryNode.getExpression()));
|
||||
@ -399,12 +423,19 @@ final class IRTranslator extends SimpleNodeVisitor {
|
||||
if (initNode instanceof FunctionNode && ((FunctionNode)initNode).isDeclared()) {
|
||||
final FunctionNode funcNode = (FunctionNode) initNode;
|
||||
|
||||
final List<? extends ExpressionTree> paramTrees
|
||||
= translateExprs(funcNode.getParameters());
|
||||
final List<? extends ExpressionTree> paramTrees = translateParameters(funcNode);
|
||||
final BlockTree blockTree = (BlockTree) translateBlock(funcNode.getBody(), true);
|
||||
curStat = new FunctionDeclarationTreeImpl(varNode, paramTrees, blockTree);
|
||||
} else if (initNode instanceof ClassNode && ((ClassNode)initNode).isStatement()) {
|
||||
final ClassNode classNode = (ClassNode) initNode;
|
||||
|
||||
curStat = new ClassDeclarationTreeImpl(varNode,
|
||||
translateIdent(classNode.getIdent()),
|
||||
translateExpr(classNode.getClassHeritage()),
|
||||
translateProperty(classNode.getConstructor()),
|
||||
translateProperties(classNode.getClassElements()));
|
||||
} else {
|
||||
curStat = new VariableTreeImpl(varNode, translateExpr(initNode));
|
||||
curStat = new VariableTreeImpl(varNode, translateIdent(varNode.getName()), translateExpr(initNode));
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -433,6 +464,25 @@ final class IRTranslator extends SimpleNodeVisitor {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for entering a ClassNode
|
||||
*
|
||||
* @param classNode the node
|
||||
* @return true if traversal should continue and node children be traversed, false otherwise
|
||||
*/
|
||||
@Override
|
||||
public boolean enterClassNode(final ClassNode classNode) {
|
||||
assert !classNode.isStatement(): "should not reach here for class declaration";
|
||||
|
||||
curExpr = new ClassExpressionTreeImpl(classNode,
|
||||
translateIdent(classNode.getIdent()),
|
||||
translateExpr(classNode.getClassHeritage()),
|
||||
translateProperty(classNode.getConstructor()),
|
||||
translateProperties(classNode.getClassElements()));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private StatementTree translateBlock(final Block blockNode) {
|
||||
return translateBlock(blockNode, false);
|
||||
}
|
||||
@ -493,6 +543,24 @@ final class IRTranslator extends SimpleNodeVisitor {
|
||||
return statTrees;
|
||||
}
|
||||
|
||||
private List<? extends ExpressionTree> translateParameters(final FunctionNode func) {
|
||||
Map<IdentNode, Expression> paramExprs = func.getParameterExpressions();
|
||||
if (paramExprs != null) {
|
||||
List<IdentNode> params = func.getParameters();
|
||||
final List<ExpressionTreeImpl> exprTrees = new ArrayList<>(params.size());
|
||||
for (final IdentNode ident : params) {
|
||||
Expression expr = paramExprs.containsKey(ident)? paramExprs.get(ident) : ident;
|
||||
curExpr = null;
|
||||
expr.accept(this);
|
||||
assert curExpr != null;
|
||||
exprTrees.add(curExpr);
|
||||
}
|
||||
return exprTrees;
|
||||
} else {
|
||||
return translateExprs(func.getParameters());
|
||||
}
|
||||
}
|
||||
|
||||
private List<? extends ExpressionTree> translateExprs(final List<? extends Expression> exprs) {
|
||||
if (exprs == null) {
|
||||
return null;
|
||||
@ -532,4 +600,25 @@ final class IRTranslator extends SimpleNodeVisitor {
|
||||
private static IdentifierTree translateIdent(final IdentNode ident) {
|
||||
return new IdentifierTreeImpl(ident);
|
||||
}
|
||||
|
||||
private List<? extends PropertyTree> translateProperties(final List<PropertyNode> propNodes) {
|
||||
final List<PropertyTree> propTrees = new ArrayList<>(propNodes.size());
|
||||
for (final PropertyNode propNode : propNodes) {
|
||||
propTrees.add(translateProperty(propNode));
|
||||
}
|
||||
return propTrees;
|
||||
}
|
||||
|
||||
private PropertyTree translateProperty(final PropertyNode propNode) {
|
||||
return new PropertyTreeImpl(propNode,
|
||||
translateExpr(propNode.getKey()),
|
||||
translateExpr(propNode.getValue()),
|
||||
(FunctionExpressionTree) translateExpr(propNode.getGetter()),
|
||||
(FunctionExpressionTree) translateExpr(propNode.getSetter()));
|
||||
}
|
||||
|
||||
private ModuleTree translateModule(final FunctionNode func) {
|
||||
return func.getKind() == FunctionNode.Kind.MODULE?
|
||||
ModuleTreeImpl.create(func) : null;
|
||||
}
|
||||
}
|
||||
|
@ -42,4 +42,46 @@ public interface IdentifierTree extends ExpressionTree {
|
||||
* @return the name of this identifier
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Is this a rest parameter for a function or rest elements of an array?
|
||||
*
|
||||
* @return true if this is a rest parameter
|
||||
*/
|
||||
boolean isRestParameter();
|
||||
|
||||
/**
|
||||
* Is this super identifier?
|
||||
*
|
||||
* @return true if this is super identifier
|
||||
*/
|
||||
boolean isSuper();
|
||||
|
||||
/**
|
||||
* Is this 'this' identifier?
|
||||
*
|
||||
* @return true if this is 'this' identifier
|
||||
*/
|
||||
boolean isThis();
|
||||
|
||||
/**
|
||||
* Is this "*" used in module export entry?
|
||||
*
|
||||
* @return true if this "*" used in module export entry?
|
||||
*/
|
||||
boolean isStar();
|
||||
|
||||
/**
|
||||
* Is this "default" used in module export entry?
|
||||
*
|
||||
* @return true if this 'default' used in module export entry?
|
||||
*/
|
||||
boolean isDefault();
|
||||
|
||||
/**
|
||||
* Is this "*default*" used in module export entry?
|
||||
*
|
||||
* @return true if this '*default*' used in module export entry?
|
||||
*/
|
||||
boolean isStarDefaultStar();
|
||||
}
|
||||
|
@ -27,6 +27,7 @@
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import jdk.nashorn.internal.ir.IdentNode;
|
||||
import jdk.nashorn.internal.ir.Module;
|
||||
|
||||
final class IdentifierTreeImpl extends ExpressionTreeImpl implements IdentifierTree {
|
||||
private final String name;
|
||||
@ -46,6 +47,37 @@ final class IdentifierTreeImpl extends ExpressionTreeImpl implements IdentifierT
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRestParameter() {
|
||||
return ((IdentNode)node).isRestParameter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSuper() {
|
||||
final IdentNode ident = (IdentNode)node;
|
||||
return ident.isDirectSuper() || "super".equals(ident.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isThis() {
|
||||
return "this".equals(((IdentNode)node).getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStar() {
|
||||
return Module.STAR_NAME.equals(((IdentNode)node).getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDefault() {
|
||||
return Module.DEFAULT_NAME.equals(((IdentNode)node).getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStarDefaultStar() {
|
||||
return Module.DEFAULT_EXPORT_BINDING_NAME.equals(((IdentNode)node).getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(final TreeVisitor<R,D> visitor, final D data) {
|
||||
return visitor.visitIdentifier(this, data);
|
||||
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A Tree node for import entry of <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-modules">Module information</a>.
|
||||
*/
|
||||
public interface ImportEntryTree extends Tree {
|
||||
/**
|
||||
* Returns the entry's module request.
|
||||
*
|
||||
* @return the module request
|
||||
*/
|
||||
public IdentifierTree getModuleRequest();
|
||||
|
||||
/**
|
||||
* Returns the entry's import name.
|
||||
*
|
||||
* @return the import name
|
||||
*/
|
||||
public IdentifierTree getImportName();
|
||||
|
||||
/**
|
||||
* Returns the entry's local name.
|
||||
*
|
||||
* @return the local name
|
||||
*/
|
||||
public IdentifierTree getLocalName();
|
||||
}
|
@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import jdk.nashorn.internal.ir.FunctionNode;
|
||||
import jdk.nashorn.internal.ir.IdentNode;
|
||||
import jdk.nashorn.internal.ir.Module;
|
||||
import static jdk.nashorn.api.tree.ModuleTreeImpl.identOrNull;
|
||||
|
||||
final class ImportEntryTreeImpl extends TreeImpl implements ImportEntryTree {
|
||||
private final long startPos, endPos;
|
||||
private final IdentifierTree moduleRequest;
|
||||
private final IdentifierTree importName;
|
||||
private final IdentifierTree localName;
|
||||
|
||||
private ImportEntryTreeImpl(final long startPos, final long endPos,
|
||||
IdentifierTree moduleRequest,
|
||||
IdentifierTree importName,
|
||||
IdentifierTree localName) {
|
||||
super(null); // No underlying Node!
|
||||
this.startPos = startPos;
|
||||
this.endPos = endPos;
|
||||
this.moduleRequest = moduleRequest;
|
||||
this.importName = importName;
|
||||
this.localName = localName;
|
||||
}
|
||||
|
||||
private static ImportEntryTreeImpl createImportEntry(Module.ImportEntry entry) {
|
||||
return new ImportEntryTreeImpl(entry.getStartPosition(),
|
||||
entry.getEndPosition(),
|
||||
identOrNull(entry.getModuleRequest()),
|
||||
identOrNull(entry.getImportName()),
|
||||
identOrNull(entry.getLocalName()));
|
||||
}
|
||||
|
||||
static List<ImportEntryTreeImpl> createImportList(List<Module.ImportEntry> importList) {
|
||||
return importList.stream().
|
||||
map(ImportEntryTreeImpl::createImportEntry).
|
||||
collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Tree.Kind.IMPORT_ENTRY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(final TreeVisitor<R,D> visitor, final D data) {
|
||||
return visitor.visitImportEntry(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getStartPosition() {
|
||||
return startPos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getEndPosition() {
|
||||
return endPos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentifierTree getModuleRequest() {
|
||||
return moduleRequest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentifierTree getImportName() {
|
||||
return importName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentifierTree getLocalName() {
|
||||
return localName;
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A Tree node for <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-modules">Module information</a>.
|
||||
*/
|
||||
public interface ModuleTree extends Tree {
|
||||
/**
|
||||
* Returns the list of import entries.
|
||||
*
|
||||
* @return the import entries
|
||||
*/
|
||||
public List<? extends ImportEntryTree> getImportEntries();
|
||||
|
||||
/**
|
||||
* Returns the list of local export entries.
|
||||
*
|
||||
* @return the local export entries
|
||||
*/
|
||||
public List<? extends ExportEntryTree> getLocalExportEntries();
|
||||
|
||||
/**
|
||||
* Returns the list of indirect export entries.
|
||||
*
|
||||
* @return the indirect export entries
|
||||
*/
|
||||
public List<? extends ExportEntryTree> getIndirectExportEntries();
|
||||
|
||||
/**
|
||||
* Returns the list of star export entries.
|
||||
*
|
||||
* @return the star export entries
|
||||
*/
|
||||
public List<? extends ExportEntryTree> getStarExportEntries();
|
||||
}
|
@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import jdk.nashorn.internal.ir.FunctionNode;
|
||||
import jdk.nashorn.internal.ir.IdentNode;
|
||||
import jdk.nashorn.internal.ir.Module;
|
||||
import static jdk.nashorn.api.tree.ExportEntryTreeImpl.createExportList;
|
||||
import static jdk.nashorn.api.tree.ImportEntryTreeImpl.createImportList;
|
||||
|
||||
final class ModuleTreeImpl extends TreeImpl implements ModuleTree {
|
||||
|
||||
private final Module mod;
|
||||
private final List<? extends ImportEntryTree> imports;
|
||||
private final List<? extends ExportEntryTree> localExports;
|
||||
private final List<? extends ExportEntryTree> indirectExports;
|
||||
private final List<? extends ExportEntryTree> starExports;
|
||||
|
||||
private ModuleTreeImpl(final FunctionNode func,
|
||||
final List<? extends ImportEntryTree> imports,
|
||||
final List<? extends ExportEntryTree> localExports,
|
||||
final List<? extends ExportEntryTree> indirectExports,
|
||||
final List<? extends ExportEntryTree> starExports) {
|
||||
super(func);
|
||||
assert func.getKind() == FunctionNode.Kind.MODULE : "module function node expected";
|
||||
this.mod = func.getModule();
|
||||
this.imports = imports;
|
||||
this.localExports = localExports;
|
||||
this.indirectExports = indirectExports;
|
||||
this.starExports = starExports;
|
||||
}
|
||||
|
||||
static ModuleTreeImpl create(final FunctionNode func) {
|
||||
final Module mod = func.getModule();
|
||||
return new ModuleTreeImpl(func,
|
||||
createImportList(mod.getImportEntries()),
|
||||
createExportList(mod.getLocalExportEntries()),
|
||||
createExportList(mod.getIndirectExportEntries()),
|
||||
createExportList(mod.getStarExportEntries()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Tree.Kind.MODULE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends ImportEntryTree> getImportEntries() {
|
||||
return imports;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends ExportEntryTree> getLocalExportEntries() {
|
||||
return localExports;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends ExportEntryTree> getIndirectExportEntries() {
|
||||
return indirectExports;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends ExportEntryTree> getStarExportEntries() {
|
||||
return starExports;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(final TreeVisitor<R,D> visitor, final D data) {
|
||||
return visitor.visitModule(this, data);
|
||||
}
|
||||
|
||||
static IdentifierTree identOrNull(final IdentNode node) {
|
||||
return node != null? new IdentifierTreeImpl(node) : null;
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -130,6 +130,8 @@ public interface Parser {
|
||||
* <dt>"--no-syntax-extensions" or "-nse"</dt><dd>disable ECMAScript syntax extensions</dd>
|
||||
* <dt>"-scripting"</dt><dd>enable scripting mode extensions</dd>
|
||||
* <dt>"-strict"</dt><dd>enable ECMAScript strict mode</dd>
|
||||
* <dt>"--language=es6"</dt><dd>enable ECMAScript 6 parsing mode</dd>
|
||||
* <dt>"--es6-module"</dt><dd>enable ECMAScript 6 module parsing mode. This option implies --language=es6</dd>
|
||||
* </dl>
|
||||
*
|
||||
* @throws NullPointerException if options array or any of its element is null
|
||||
@ -148,6 +150,8 @@ public interface Parser {
|
||||
case "-nse":
|
||||
case "-scripting":
|
||||
case "-strict":
|
||||
case "--language=es6":
|
||||
case "--es6-module":
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException(opt);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -22,7 +22,6 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import java.io.File;
|
||||
@ -31,6 +30,7 @@ import java.io.PrintWriter;
|
||||
import java.io.Reader;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import jdk.nashorn.api.scripting.NashornException;
|
||||
@ -47,51 +47,94 @@ import jdk.nashorn.internal.runtime.options.Options;
|
||||
final class ParserImpl implements Parser {
|
||||
|
||||
private final ScriptEnvironment env;
|
||||
private final boolean moduleMode;
|
||||
|
||||
ParserImpl(final String... args) throws IllegalArgumentException {
|
||||
Objects.requireNonNull(args);
|
||||
Options options = new Options("nashorn");
|
||||
options.process(args);
|
||||
this.env = new ScriptEnvironment(options,
|
||||
new PrintWriter(System.out), new PrintWriter(System.err));
|
||||
Objects.requireNonNull(args);
|
||||
|
||||
// handle the parser specific "--es6-module" option
|
||||
boolean seenModuleOption = false;
|
||||
for (int idx = 0; idx < args.length; idx++) {
|
||||
final String opt = args[idx];
|
||||
if (opt.equals("--es6-module")) {
|
||||
seenModuleOption = true;
|
||||
/*
|
||||
* Nashorn parser does not understand parser API specific
|
||||
* option. This option implies --language=es6. So, we change
|
||||
* the option to --language=es6. Note that if user specified
|
||||
* --language=es6 explicitly, that is okay. Nashorn tolerates
|
||||
* repeated options!
|
||||
*/
|
||||
args[idx] = "--language=es6";
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.moduleMode = seenModuleOption;
|
||||
|
||||
// append "--parse-only to signal to the Nashorn that it
|
||||
// is being used in "parse only" mode.
|
||||
String[] newArgs = Arrays.copyOf(args, args.length + 1, String[].class);
|
||||
newArgs[args.length] = "--parse-only";
|
||||
Options options = new Options("nashorn");
|
||||
options.process(newArgs);
|
||||
this.env = new ScriptEnvironment(options,
|
||||
new PrintWriter(System.out), new PrintWriter(System.err));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompilationUnitTree parse(final File file, final DiagnosticListener listener) throws IOException, NashornException {
|
||||
if (moduleMode) {
|
||||
return parseModule(file, listener);
|
||||
}
|
||||
final Source src = Source.sourceFor(Objects.requireNonNull(file).getName(), file);
|
||||
return translate(makeParser(src, listener).parse());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompilationUnitTree parse(final Path path, final DiagnosticListener listener) throws IOException, NashornException {
|
||||
if (moduleMode) {
|
||||
return parseModule(path, listener);
|
||||
}
|
||||
final Source src = Source.sourceFor(Objects.requireNonNull(path).toString(), path);
|
||||
return translate(makeParser(src, listener).parse());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompilationUnitTree parse(final URL url, final DiagnosticListener listener) throws IOException, NashornException {
|
||||
if (moduleMode) {
|
||||
return parseModule(url, listener);
|
||||
}
|
||||
final Source src = Source.sourceFor(url.toString(), url);
|
||||
return translate(makeParser(src, listener).parse());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompilationUnitTree parse(final String name, final Reader reader, final DiagnosticListener listener) throws IOException, NashornException {
|
||||
if (moduleMode) {
|
||||
return parseModule(name, reader, listener);
|
||||
}
|
||||
final Source src = Source.sourceFor(Objects.requireNonNull(name), Objects.requireNonNull(reader));
|
||||
return translate(makeParser(src, listener).parse());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompilationUnitTree parse(final String name, final String code, final DiagnosticListener listener) throws NashornException {
|
||||
if (moduleMode) {
|
||||
return parseModule(name, code, listener);
|
||||
}
|
||||
final Source src = Source.sourceFor(name, code);
|
||||
return translate(makeParser(src, listener).parse());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompilationUnitTree parse(final ScriptObjectMirror scriptObj, final DiagnosticListener listener) throws NashornException {
|
||||
final Map<?,?> map = Objects.requireNonNull(scriptObj);
|
||||
if (moduleMode) {
|
||||
return parseModule(scriptObj, listener);
|
||||
}
|
||||
final Map<?, ?> map = Objects.requireNonNull(scriptObj);
|
||||
if (map.containsKey("script") && map.containsKey("name")) {
|
||||
final String script = JSType.toString(map.get("script"));
|
||||
final String name = JSType.toString(map.get("name"));
|
||||
final String name = JSType.toString(map.get("name"));
|
||||
final Source src = Source.sourceFor(name, script);
|
||||
return translate(makeParser(src, listener).parse());
|
||||
} else {
|
||||
@ -99,12 +142,55 @@ final class ParserImpl implements Parser {
|
||||
}
|
||||
}
|
||||
|
||||
private CompilationUnitTree parseModule(File file, DiagnosticListener listener) throws IOException, NashornException {
|
||||
final Source src = Source.sourceFor(Objects.requireNonNull(file).getName(), file);
|
||||
return makeModule(src, listener);
|
||||
}
|
||||
|
||||
private CompilationUnitTree parseModule(Path path, DiagnosticListener listener) throws IOException, NashornException {
|
||||
final Source src = Source.sourceFor(Objects.requireNonNull(path).toString(), path);
|
||||
return makeModule(src, listener);
|
||||
}
|
||||
|
||||
private CompilationUnitTree parseModule(URL url, DiagnosticListener listener) throws IOException, NashornException {
|
||||
final Source src = Source.sourceFor(url.toString(), url);
|
||||
return makeModule(src, listener);
|
||||
}
|
||||
|
||||
private CompilationUnitTree parseModule(String name, Reader reader, DiagnosticListener listener) throws IOException, NashornException {
|
||||
final Source src = Source.sourceFor(Objects.requireNonNull(name), Objects.requireNonNull(reader));
|
||||
return makeModule(src, listener);
|
||||
}
|
||||
|
||||
private CompilationUnitTree parseModule(String name, String code, DiagnosticListener listener) throws NashornException {
|
||||
final Source src = Source.sourceFor(name, code);
|
||||
return makeModule(src, listener);
|
||||
}
|
||||
|
||||
private CompilationUnitTree parseModule(ScriptObjectMirror scriptObj, DiagnosticListener listener) throws NashornException {
|
||||
final Map<?, ?> map = Objects.requireNonNull(scriptObj);
|
||||
if (map.containsKey("script") && map.containsKey("name")) {
|
||||
final String script = JSType.toString(map.get("script"));
|
||||
final String name = JSType.toString(map.get("name"));
|
||||
final Source src = Source.sourceFor(name, script);
|
||||
return makeModule(src, listener);
|
||||
} else {
|
||||
throw new IllegalArgumentException("can't find 'script' and 'name' properties");
|
||||
}
|
||||
}
|
||||
|
||||
private CompilationUnitTree makeModule(Source src, DiagnosticListener listener) {
|
||||
final FunctionNode modFunc = makeParser(src, listener).parseModule(src.getName());
|
||||
return new IRTranslator().translate(modFunc);
|
||||
}
|
||||
|
||||
private jdk.nashorn.internal.parser.Parser makeParser(final Source source, final DiagnosticListener listener) {
|
||||
final ErrorManager errMgr = listener != null? new ListenerErrorManager(listener) : new Context.ThrowErrorManager();
|
||||
final ErrorManager errMgr = listener != null ? new ListenerErrorManager(listener) : new Context.ThrowErrorManager();
|
||||
return new jdk.nashorn.internal.parser.Parser(env, source, errMgr);
|
||||
}
|
||||
|
||||
private static class ListenerErrorManager extends ErrorManager {
|
||||
|
||||
private final DiagnosticListener listener;
|
||||
|
||||
ListenerErrorManager(final DiagnosticListener listener) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -60,4 +60,18 @@ public interface PropertyTree extends Tree {
|
||||
* @return the getter function of the property
|
||||
*/
|
||||
public FunctionExpressionTree getSetter();
|
||||
|
||||
/**
|
||||
* Is this a class static property?
|
||||
*
|
||||
* @return true if this is a static property
|
||||
*/
|
||||
public boolean isStatic();
|
||||
|
||||
/**
|
||||
* Is this a computed property?
|
||||
*
|
||||
* @return true if this is a computed property
|
||||
*/
|
||||
public boolean isComputed();
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -32,6 +32,8 @@ final class PropertyTreeImpl extends TreeImpl implements PropertyTree {
|
||||
private final ExpressionTree value;
|
||||
private final FunctionExpressionTree getter;
|
||||
private final FunctionExpressionTree setter;
|
||||
private final boolean isStatic, isComputed;
|
||||
|
||||
PropertyTreeImpl(final PropertyNode node,
|
||||
final ExpressionTree key,
|
||||
final ExpressionTree value,
|
||||
@ -42,6 +44,8 @@ final class PropertyTreeImpl extends TreeImpl implements PropertyTree {
|
||||
this.value = value;
|
||||
this.getter = getter;
|
||||
this.setter = setter;
|
||||
this.isStatic = node.isStatic();
|
||||
this.isComputed = node.isComputed();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -69,6 +73,16 @@ final class PropertyTreeImpl extends TreeImpl implements PropertyTree {
|
||||
return setter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStatic() {
|
||||
return isStatic;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isComputed() {
|
||||
return isComputed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(final TreeVisitor<R,D> visitor, final D data) {
|
||||
return visitor.visitProperty(this, data);
|
||||
|
@ -30,7 +30,7 @@ package jdk.nashorn.api.tree;
|
||||
*
|
||||
* @since 9
|
||||
*/
|
||||
public interface RegExpLiteralTree extends Tree {
|
||||
public interface RegExpLiteralTree extends ExpressionTree {
|
||||
/**
|
||||
* Regular expression pattern to match.
|
||||
*
|
||||
|
@ -61,6 +61,45 @@ public class SimpleTreeVisitorES5_1<R, P> implements TreeVisitor<R, P> {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits a {@code ModuleTree} tree by calling {@code
|
||||
* visitUnknown}.
|
||||
*
|
||||
* @param node {@inheritDoc}
|
||||
* @param p {@inheritDoc}
|
||||
* @return the result of {@code visitUnknown}
|
||||
*/
|
||||
@Override
|
||||
public R visitModule(ModuleTree node, P p) {
|
||||
return visitUnknown(node, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits an {@code ExportEntryTree} tree by calling {@code
|
||||
* visitUnknown}.
|
||||
*
|
||||
* @param node {@inheritDoc}
|
||||
* @param p {@inheritDoc}
|
||||
* @return the result of {@code visitUnknown}
|
||||
*/
|
||||
@Override
|
||||
public R visitExportEntry(ExportEntryTree node, P p) {
|
||||
return visitUnknown(node, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits an {@code ImportEntryTree} tree by calling {@code
|
||||
* visitUnknown}.
|
||||
*
|
||||
* @param node {@inheritDoc}
|
||||
* @param p {@inheritDoc}
|
||||
* @return the result of {@code visitUnknown}
|
||||
*/
|
||||
@Override
|
||||
public R visitImportEntry(ImportEntryTree node, P p) {
|
||||
return visitUnknown(node, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitBinary(final BinaryTree node, final P r) {
|
||||
node.getLeftOperand().accept(this, r);
|
||||
@ -105,6 +144,32 @@ public class SimpleTreeVisitorES5_1<R, P> implements TreeVisitor<R, P> {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits a {@code ClassDeclarationTree} tree by calling {@code
|
||||
* visitUnknown}.
|
||||
*
|
||||
* @param node {@inheritDoc}
|
||||
* @param p {@inheritDoc}
|
||||
* @return the result of {@code visitUnknown}
|
||||
*/
|
||||
@Override
|
||||
public R visitClassDeclaration(ClassDeclarationTree node, P p) {
|
||||
return visitUnknown(node, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits a {@code ClassExpressionTree} tree by calling {@code
|
||||
* visitUnknown}.
|
||||
*
|
||||
* @param node {@inheritDoc}
|
||||
* @param p {@inheritDoc}
|
||||
* @return the result of {@code visitUnknown}
|
||||
*/
|
||||
@Override
|
||||
public R visitClassExpression(ClassExpressionTree node, P p) {
|
||||
return visitUnknown(node, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitConditionalExpression(final ConditionalExpressionTree node, final P r) {
|
||||
node.getCondition().accept(this, r);
|
||||
@ -173,6 +238,19 @@ public class SimpleTreeVisitorES5_1<R, P> implements TreeVisitor<R, P> {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits a {@code ForOfLoopTree} tree by calling {@code
|
||||
* visitUnknown}.
|
||||
*
|
||||
* @param node {@inheritDoc}
|
||||
* @param p {@inheritDoc}
|
||||
* @return the result of {@code visitUnknown}
|
||||
*/
|
||||
@Override
|
||||
public R visitForOfLoop(ForOfLoopTree node, P p) {
|
||||
return visitUnknown(node, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitFunctionCall(final FunctionCallTree node, final P r) {
|
||||
node.getFunctionSelect().accept(this, r);
|
||||
@ -305,11 +383,37 @@ public class SimpleTreeVisitorES5_1<R, P> implements TreeVisitor<R, P> {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits a {@code TemplateLiteralTree} tree by calling {@code
|
||||
* visitUnknown}.
|
||||
*
|
||||
* @param node {@inheritDoc}
|
||||
* @param p {@inheritDoc}
|
||||
* @return the result of {@code visitUnknown}
|
||||
*/
|
||||
@Override
|
||||
public R visitTemplateLiteral(TemplateLiteralTree node, P p) {
|
||||
return visitUnknown(node, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitEmptyStatement(final EmptyStatementTree node, final P r) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits a {@code SpreadTree} tree by calling {@code
|
||||
* visitUnknown}.
|
||||
*
|
||||
* @param node {@inheritDoc}
|
||||
* @param p {@inheritDoc}
|
||||
* @return the result of {@code visitUnknown}
|
||||
*/
|
||||
@Override
|
||||
public R visitSpread(SpreadTree node, P p) {
|
||||
return visitUnknown(node, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitSwitch(final SwitchTree node, final P r) {
|
||||
node.getExpression().accept(this, r);
|
||||
@ -382,9 +486,36 @@ public class SimpleTreeVisitorES5_1<R, P> implements TreeVisitor<R, P> {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits a {@code YieldTree} tree by calling {@code
|
||||
* visitUnknown}.
|
||||
*
|
||||
* @param node {@inheritDoc}
|
||||
* @param p {@inheritDoc}
|
||||
* @return the result of {@code visitUnknown}
|
||||
*/
|
||||
@Override
|
||||
public R visitUnknown(final Tree node, final P r) {
|
||||
public R visitYield(YieldTree node, P p) {
|
||||
return visitUnknown(node, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @implSpec The default implementation of this method in {@code
|
||||
* SimpleTreeVisitorES5_1} will always throw {@code
|
||||
* UnknownTypeException}. This behavior is not required of a
|
||||
* subclass.
|
||||
*
|
||||
* @param node {@inheritDoc}
|
||||
* @param p {@inheritDoc}
|
||||
* @return abnormal return by throwing exception always
|
||||
* @throws UnknownTreeException
|
||||
* a visitor implementation may optionally throw this exception
|
||||
*/
|
||||
@Override
|
||||
public R visitUnknown(final Tree node, final P p) {
|
||||
// unknown in ECMAScript 5.1 edition
|
||||
throw new UnknownTreeException(node, r);
|
||||
throw new UnknownTreeException(node, p);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,226 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A simple implementation of the TreeVisitor for ECMAScript edition 6.
|
||||
*
|
||||
* <p>The visit methods corresponding to ES 6 language constructs walk the
|
||||
* "components" of the given tree by calling accept method passing the
|
||||
* current visitor and the additional parameter.
|
||||
*
|
||||
* <p>For constructs introduced in later versions, {@code visitUnknown}
|
||||
* is called instead which throws {@link UnknownTreeException}.
|
||||
*
|
||||
* <p> Methods in this class may be overridden subject to their
|
||||
* general contract. Note that annotating methods in concrete
|
||||
* subclasses with {@link java.lang.Override @Override} will help
|
||||
* ensure that methods are overridden as intended.
|
||||
*
|
||||
* @param <R> the return type of this visitor's methods. Use {@link
|
||||
* Void} for visitors that do not need to return results.
|
||||
* @param <P> the type of the additional parameter to this visitor's
|
||||
* methods. Use {@code Void} for visitors that do not need an
|
||||
* additional parameter.
|
||||
*/
|
||||
public class SimpleTreeVisitorES6<R, P> extends SimpleTreeVisitorES5_1<R, P> {
|
||||
@Override
|
||||
public R visitCompilationUnit(final CompilationUnitTree node, final P r) {
|
||||
final ModuleTree mod = node.getModule();
|
||||
if (mod != null) {
|
||||
mod.accept(this, r);
|
||||
}
|
||||
return super.visitCompilationUnit(node, r);
|
||||
}
|
||||
|
||||
/**
|
||||
* Visit Module tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
@Override
|
||||
public R visitModule(ModuleTree node, P p) {
|
||||
node.getImportEntries().forEach(e -> visitImportEntry(e, p));
|
||||
node.getLocalExportEntries().forEach(e -> visitExportEntry(e, p));
|
||||
node.getIndirectExportEntries().forEach(e -> visitExportEntry(e, p));
|
||||
node.getStarExportEntries().forEach(e -> visitExportEntry(e, p));
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Visit Module ExportEntry tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
@Override
|
||||
public R visitExportEntry(ExportEntryTree node, P p) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Visit Module ImportEntry tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
@Override
|
||||
public R visitImportEntry(ImportEntryTree node, P p) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Visit class statement tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
@Override
|
||||
public R visitClassDeclaration(ClassDeclarationTree node, P p) {
|
||||
node.getName().accept(this, p);
|
||||
final ExpressionTree heritage = node.getClassHeritage();
|
||||
if (heritage != null) {
|
||||
heritage.accept(this, p);
|
||||
}
|
||||
final PropertyTree constructor = node.getConstructor();
|
||||
if (constructor != null) {
|
||||
constructor.accept(this, p);
|
||||
}
|
||||
final List<? extends PropertyTree> elements = node.getClassElements();
|
||||
if (elements != null) {
|
||||
for (PropertyTree prop : elements) {
|
||||
prop.accept(this, p);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Visit class expression tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
@Override
|
||||
public R visitClassExpression(ClassExpressionTree node, P p) {
|
||||
node.getName().accept(this, p);
|
||||
final ExpressionTree heritage = node.getClassHeritage();
|
||||
if (heritage != null) {
|
||||
heritage.accept(this, p);
|
||||
}
|
||||
final PropertyTree constructor = node.getConstructor();
|
||||
if (constructor != null) {
|
||||
constructor.accept(this, p);
|
||||
}
|
||||
final List<? extends PropertyTree> elements = node.getClassElements();
|
||||
if (elements != null) {
|
||||
for (PropertyTree prop : elements) {
|
||||
prop.accept(this, p);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Visit for..of statement tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
@Override
|
||||
public R visitForOfLoop(final ForOfLoopTree node, final P p) {
|
||||
node.getVariable().accept(this, p);
|
||||
node.getExpression().accept(this, p);
|
||||
final StatementTree stat = node.getStatement();
|
||||
if (stat != null) {
|
||||
stat.accept(this, p);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Visit 'yield' expression tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
@Override
|
||||
public R visitYield(YieldTree node, P p) {
|
||||
node.getExpression().accept(this, p);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Visit 'spread' expression tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
@Override
|
||||
public R visitSpread(SpreadTree node, P p) {
|
||||
node.getExpression().accept(this, p);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Visit template literal tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
@Override
|
||||
public R visitTemplateLiteral(TemplateLiteralTree node, P p) {
|
||||
final List<? extends ExpressionTree> expressions = node.getExpressions();
|
||||
for (ExpressionTree expr : expressions) {
|
||||
expr.accept(this, p);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitVariable(final VariableTree node, final P r) {
|
||||
final ExpressionTree expr = node.getBinding();
|
||||
if (expr != null) {
|
||||
expr.accept(this, r);
|
||||
}
|
||||
super.visitVariable(node, r);
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
/**
|
||||
* A tree node for spread operator in array elements, function call arguments.
|
||||
*/
|
||||
public interface SpreadTree extends ExpressionTree {
|
||||
/**
|
||||
* Returns the expression that is being spread.
|
||||
*
|
||||
* @return The expression that is being spread.
|
||||
*/
|
||||
ExpressionTree getExpression();
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import jdk.nashorn.internal.ir.Expression;
|
||||
|
||||
final class SpreadTreeImpl extends ExpressionTreeImpl
|
||||
implements SpreadTree {
|
||||
|
||||
private final ExpressionTree expr;
|
||||
|
||||
SpreadTreeImpl(final Expression exprNode, final ExpressionTree expr) {
|
||||
super(exprNode);
|
||||
this.expr = expr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tree.Kind getKind() {
|
||||
return Tree.Kind.SPREAD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionTree getExpression() {
|
||||
return expr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(final TreeVisitor<R,D> visitor, final D data) {
|
||||
return visitor.visitSpread(this, data);
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A tree node for <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-template-literals">template literal strings</a>.
|
||||
*
|
||||
* For example:
|
||||
* <pre>
|
||||
* `This is a String with ${computed} values in it`
|
||||
* </pre>
|
||||
*
|
||||
* @since 9
|
||||
*
|
||||
*/
|
||||
public interface TemplateLiteralTree extends ExpressionTree {
|
||||
/**
|
||||
* Returns the list of expressions in this template string
|
||||
*
|
||||
* @return the list of expressions in this template string
|
||||
*/
|
||||
List<? extends ExpressionTree> getExpressions();
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import java.util.List;
|
||||
import jdk.nashorn.internal.ir.Expression;
|
||||
|
||||
final class TemplateLiteralTreeImpl extends ExpressionTreeImpl
|
||||
implements TemplateLiteralTree {
|
||||
|
||||
private final List<? extends ExpressionTree> expressions;
|
||||
|
||||
TemplateLiteralTreeImpl(Expression node, List<? extends ExpressionTree> expressions) {
|
||||
super(node);
|
||||
this.expressions = expressions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.TEMPLATE_LITERAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends ExpressionTree> getExpressions() {
|
||||
return expressions;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(final TreeVisitor<R,D> visitor, final D data) {
|
||||
return visitor.visitTemplateLiteral(this, data);
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -64,6 +64,16 @@ public interface Tree {
|
||||
*/
|
||||
BREAK(BreakTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link ClassDeclarationTree}.
|
||||
*/
|
||||
CLASS(ClassDeclarationTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link ClassExpressionTree}.
|
||||
*/
|
||||
CLASS_EXPRESSION(ClassExpressionTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link CaseTree}.
|
||||
*/
|
||||
@ -149,6 +159,21 @@ public interface Tree {
|
||||
*/
|
||||
LABELED_STATEMENT(LabeledStatementTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link ModuleTree}.
|
||||
*/
|
||||
MODULE(ModuleTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link ExportEntryTree}.
|
||||
*/
|
||||
EXPORT_ENTRY(ExportEntryTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link ImportEntryTree}.
|
||||
*/
|
||||
IMPORT_ENTRY(ImportEntryTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link FunctionDeclarationTree}.
|
||||
*/
|
||||
@ -184,6 +209,11 @@ public interface Tree {
|
||||
*/
|
||||
REGEXP_LITERAL(RegExpLiteralTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link TemplateLiteralTree}.
|
||||
*/
|
||||
TEMPLATE_LITERAL(TemplateLiteralTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link ReturnTree}.
|
||||
*/
|
||||
@ -286,7 +316,7 @@ public interface Tree {
|
||||
|
||||
/**
|
||||
* Used for instances of {@link UnaryTree} representing logical
|
||||
* void operator {@code typeof}.
|
||||
* void operator {@code void}.
|
||||
*/
|
||||
VOID(UnaryTree.class),
|
||||
|
||||
@ -494,6 +524,18 @@ public interface Tree {
|
||||
*/
|
||||
OR_ASSIGNMENT(CompoundAssignmentTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link SpreadTree} representing
|
||||
* spread "operator" for arrays and function call arguments.
|
||||
*/
|
||||
SPREAD(SpreadTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link YieldTree} representing (generator)
|
||||
* yield expression {@code yield expr}.
|
||||
*/
|
||||
YIELD(YieldTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link LiteralTree} representing
|
||||
* a number literal expression of type {@code double}.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -137,10 +137,15 @@ abstract class TreeImpl implements Tree {
|
||||
return Kind.BITWISE_COMPLEMENT;
|
||||
case DELETE:
|
||||
return Kind.DELETE;
|
||||
case SPREAD_ARRAY:
|
||||
case SPREAD_ARGUMENT:
|
||||
return Kind.SPREAD;
|
||||
case TYPEOF:
|
||||
return Kind.TYPEOF;
|
||||
case VOID:
|
||||
return Kind.VOID;
|
||||
case YIELD:
|
||||
return Kind.YIELD;
|
||||
case IN:
|
||||
return Kind.IN;
|
||||
case INSTANCEOF:
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -117,6 +117,24 @@ public interface TreeVisitor<R,P> {
|
||||
*/
|
||||
R visitCatch(CatchTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit class statement tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitClassDeclaration(ClassDeclarationTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit class expression tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitClassExpression(ClassExpressionTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit conditional expression tree.
|
||||
*
|
||||
@ -189,6 +207,15 @@ public interface TreeVisitor<R,P> {
|
||||
*/
|
||||
R visitForInLoop(ForInLoopTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit for..of statement tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitForOfLoop(ForOfLoopTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit function call expression tree.
|
||||
*
|
||||
@ -216,7 +243,7 @@ public interface TreeVisitor<R,P> {
|
||||
*/
|
||||
R visitFunctionExpression(FunctionExpressionTree node, P p);
|
||||
|
||||
/**
|
||||
/**
|
||||
* Visit identifier tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
@ -333,6 +360,15 @@ public interface TreeVisitor<R,P> {
|
||||
*/
|
||||
R visitRegExpLiteral(RegExpLiteralTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit template literal tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitTemplateLiteral(TemplateLiteralTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit an empty statement tree.
|
||||
*
|
||||
@ -342,6 +378,15 @@ public interface TreeVisitor<R,P> {
|
||||
*/
|
||||
R visitEmptyStatement(EmptyStatementTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit 'spread' expression tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitSpread(SpreadTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit 'switch' statement tree.
|
||||
*
|
||||
@ -369,6 +414,33 @@ public interface TreeVisitor<R,P> {
|
||||
*/
|
||||
R visitCompilationUnit(CompilationUnitTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit Module tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitModule(ModuleTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit Module ExportEntry tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitExportEntry(ExportEntryTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit Module ImportEntry tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitImportEntry(ImportEntryTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit 'try' statement tree.
|
||||
*
|
||||
@ -423,6 +495,15 @@ public interface TreeVisitor<R,P> {
|
||||
*/
|
||||
R visitWith(WithTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit 'yield' expression tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitYield(YieldTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit unknown expression/statement tree. This fallback will be
|
||||
* called if new Tree subtypes are introduced in future. A specific
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -26,22 +26,26 @@
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
/**
|
||||
* A tree node for a variable declaration.
|
||||
* A tree node for a <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-variable-statement">variable declaration statement</a>.
|
||||
*
|
||||
* For example:
|
||||
* <pre>
|
||||
* <em>var</em> <em>name</em> <em>initializer</em> ;
|
||||
* <em>var</em> <em>name</em> [ <em>initializer</em> ] ;
|
||||
* <em>var</em> <em>binding_pattern</em> [ <em>initializer</em> ];
|
||||
* </pre>
|
||||
*
|
||||
* @since 9
|
||||
*/
|
||||
public interface VariableTree extends StatementTree {
|
||||
/**
|
||||
* Returns the name of this variable.
|
||||
* Returns the binding of this declaration. This is an {@link IdentifierTree}
|
||||
* for a binding identifier case (simple variable declaration).
|
||||
* This is an {@link ObjectLiteralTree} or a {@link ArrayLiteralTree} for a
|
||||
* destructuring declaration.
|
||||
*
|
||||
* @return the name of this variable
|
||||
* @return the binding expression of this declaration
|
||||
*/
|
||||
String getName();
|
||||
ExpressionTree getBinding();
|
||||
|
||||
/**
|
||||
* Returns the initial value expression for this variable. This is
|
||||
@ -50,4 +54,18 @@ public interface VariableTree extends StatementTree {
|
||||
* @return the initial value expression
|
||||
*/
|
||||
ExpressionTree getInitializer();
|
||||
|
||||
/**
|
||||
* Is this a const declaration?
|
||||
*
|
||||
* @return true if this is a const declaration
|
||||
*/
|
||||
boolean isConst();
|
||||
|
||||
/**
|
||||
* Is this a let declaration?
|
||||
*
|
||||
* @return true if this is a let declaration
|
||||
*/
|
||||
boolean isLet();
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -28,12 +28,12 @@ package jdk.nashorn.api.tree;
|
||||
import jdk.nashorn.internal.ir.VarNode;
|
||||
|
||||
final class VariableTreeImpl extends StatementTreeImpl implements VariableTree {
|
||||
private final String name;
|
||||
private final IdentifierTree ident;
|
||||
private final ExpressionTree init;
|
||||
|
||||
VariableTreeImpl(final VarNode node, final ExpressionTree init) {
|
||||
VariableTreeImpl(final VarNode node, final IdentifierTree ident, final ExpressionTree init) {
|
||||
super(node);
|
||||
this.name = node.getName().getName();
|
||||
this.ident = ident;
|
||||
this.init = init;
|
||||
}
|
||||
|
||||
@ -43,8 +43,8 @@ final class VariableTreeImpl extends StatementTreeImpl implements VariableTree {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
public ExpressionTree getBinding() {
|
||||
return ident;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -52,6 +52,16 @@ final class VariableTreeImpl extends StatementTreeImpl implements VariableTree {
|
||||
return init;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConst() {
|
||||
return ((VarNode)node).isConst();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLet() {
|
||||
return ((VarNode)node).isLet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(final TreeVisitor<R,D> visitor, final D data) {
|
||||
return visitor.visitVariable(this, data);
|
||||
|
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
/**
|
||||
* A tree node for <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-generator-function-definitions">yield expressions</a> used in generator functions.
|
||||
*
|
||||
* For example:
|
||||
* <pre>
|
||||
* <em>function*</em> id(){
|
||||
* var index = 0;
|
||||
* while(index < 10)
|
||||
* <em>yield index++;</em>
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* @since 9
|
||||
*/
|
||||
public interface YieldTree extends ExpressionTree {
|
||||
/**
|
||||
* Returns the expression that is yielded.
|
||||
*
|
||||
* @return The expression that is yielded.
|
||||
*/
|
||||
ExpressionTree getExpression();
|
||||
|
||||
/**
|
||||
* Is this a yield * expression in a generator function?
|
||||
*
|
||||
* For example:
|
||||
* <pre>
|
||||
* function* id(){
|
||||
* yield 1;
|
||||
* <em>yield * anotherGeneratorFunc();</em>
|
||||
* yield 10;
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* @return true if this is a yield * expression
|
||||
*/
|
||||
boolean isStar();
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import jdk.nashorn.internal.ir.Expression;
|
||||
import jdk.nashorn.internal.ir.UnaryNode;
|
||||
import jdk.nashorn.internal.parser.TokenType;
|
||||
|
||||
final class YieldTreeImpl extends ExpressionTreeImpl
|
||||
implements YieldTree {
|
||||
|
||||
private final ExpressionTree expr;
|
||||
|
||||
YieldTreeImpl(final Expression exprNode, final ExpressionTree expr) {
|
||||
super(exprNode);
|
||||
this.expr = expr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.YIELD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionTree getExpression() {
|
||||
return expr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStar() {
|
||||
return ((UnaryNode) node).isTokenType(TokenType.YIELD_STAR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(final TreeVisitor<R,D> visitor, final D data) {
|
||||
return visitor.visitYield(this, data);
|
||||
}
|
||||
}
|
@ -167,6 +167,7 @@ final class SplitIntoFunctions extends NodeVisitor<BlockLexicalContext> {
|
||||
createIdent(name),
|
||||
originalFn.getName() + "$" + name,
|
||||
isProgram ? Collections.singletonList(createReturnParamIdent()) : Collections.<IdentNode>emptyList(),
|
||||
null,
|
||||
FunctionNode.Kind.NORMAL,
|
||||
// We only need IS_SPLIT conservatively, in case it contains any array units so that we force
|
||||
// the :callee's existence, to force :scope to never be in a slot lower than 2. This is actually
|
||||
|
@ -42,6 +42,7 @@ public class ClassNode extends Expression {
|
||||
private final PropertyNode constructor;
|
||||
private final List<PropertyNode> classElements;
|
||||
private final int line;
|
||||
private final boolean isStatement;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@ -53,15 +54,17 @@ public class ClassNode extends Expression {
|
||||
* @param classHeritage class heritage
|
||||
* @param constructor constructor
|
||||
* @param classElements class elements
|
||||
* @param isStatement is this a statement or an expression?
|
||||
*/
|
||||
public ClassNode(final int line, final long token, final int finish, final IdentNode ident, final Expression classHeritage, final PropertyNode constructor,
|
||||
final List<PropertyNode> classElements) {
|
||||
final List<PropertyNode> classElements, final boolean isStatement) {
|
||||
super(token, finish);
|
||||
this.line = line;
|
||||
this.ident = ident;
|
||||
this.classHeritage = classHeritage;
|
||||
this.constructor = constructor;
|
||||
this.classElements = classElements;
|
||||
this.isStatement = isStatement;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -100,6 +103,15 @@ public class ClassNode extends Expression {
|
||||
return Collections.unmodifiableList(classElements);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if this class was a statement or an expression
|
||||
*
|
||||
* @return true if this class was a statement
|
||||
*/
|
||||
public boolean isStatement() {
|
||||
return isStatement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the line number.
|
||||
*
|
||||
|
@ -27,6 +27,7 @@ package jdk.nashorn.internal.ir;
|
||||
|
||||
import jdk.nashorn.internal.ir.annotations.Immutable;
|
||||
import jdk.nashorn.internal.ir.visitor.NodeVisitor;
|
||||
import jdk.nashorn.internal.parser.TokenType;
|
||||
|
||||
/**
|
||||
* IR representation for executing bare expressions. Basically, an expression
|
||||
@ -39,6 +40,23 @@ public final class ExpressionStatement extends Statement {
|
||||
|
||||
/** Expression to execute. */
|
||||
private final Expression expression;
|
||||
private final TokenType destructuringDecl;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param lineNumber line number
|
||||
* @param token token
|
||||
* @param finish finish
|
||||
* @param expression the expression to execute
|
||||
* @param destructuringDecl does this statement represent a destructuring declaration?
|
||||
*/
|
||||
public ExpressionStatement(final int lineNumber, final long token, final int finish,
|
||||
final Expression expression, final TokenType destructuringDecl) {
|
||||
super(lineNumber, token, finish);
|
||||
this.expression = expression;
|
||||
this.destructuringDecl = destructuringDecl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@ -49,13 +67,13 @@ public final class ExpressionStatement extends Statement {
|
||||
* @param expression the expression to execute
|
||||
*/
|
||||
public ExpressionStatement(final int lineNumber, final long token, final int finish, final Expression expression) {
|
||||
super(lineNumber, token, finish);
|
||||
this.expression = expression;
|
||||
this(lineNumber, token, finish, expression, null);
|
||||
}
|
||||
|
||||
private ExpressionStatement(final ExpressionStatement expressionStatement, final Expression expression) {
|
||||
super(expressionStatement);
|
||||
this.expression = expression;
|
||||
this.destructuringDecl = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -80,6 +98,15 @@ public final class ExpressionStatement extends Statement {
|
||||
return expression;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return declaration type if this expression statement is a destructuring declaration
|
||||
*
|
||||
* @return declaration type (LET, VAR, CONST) if destructuring declaration, null otherwise.
|
||||
*/
|
||||
public TokenType destructuringDeclarationType() {
|
||||
return destructuringDecl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the expression to be executed
|
||||
* @param expression the expression
|
||||
|
@ -35,6 +35,7 @@ import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALL
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import jdk.nashorn.internal.codegen.CompileUnit;
|
||||
import jdk.nashorn.internal.codegen.Compiler;
|
||||
import jdk.nashorn.internal.codegen.CompilerConstants;
|
||||
@ -106,6 +107,9 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
/** List of parameters. */
|
||||
private final List<IdentNode> parameters;
|
||||
|
||||
/** Map of ES6 function parameter expressions. */
|
||||
private final Map<IdentNode, Expression> parameterExpressions;
|
||||
|
||||
/** First token of function. **/
|
||||
private final long firstToken;
|
||||
|
||||
@ -242,6 +246,9 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
/** Does this function use new.target? */
|
||||
public static final int ES6_USES_NEW_TARGET = 1 << 25;
|
||||
|
||||
/** Does this function have expression as its body? */
|
||||
public static final int HAS_EXPRESSION_BODY = 1 << 26;
|
||||
|
||||
/** Does this function or any nested functions contain an eval? */
|
||||
private static final int HAS_DEEP_EVAL = HAS_EVAL | HAS_NESTED_EVAL;
|
||||
|
||||
@ -306,6 +313,7 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
* @param ident the identifier
|
||||
* @param name the name of the function
|
||||
* @param parameters parameter list
|
||||
* @param paramExprs the ES6 function parameter expressions
|
||||
* @param kind kind of function as in {@link FunctionNode.Kind}
|
||||
* @param flags initial flags
|
||||
* @param body body of the function
|
||||
@ -324,6 +332,7 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
final IdentNode ident,
|
||||
final String name,
|
||||
final List<IdentNode> parameters,
|
||||
final Map<IdentNode, Expression> paramExprs,
|
||||
final FunctionNode.Kind kind,
|
||||
final int flags,
|
||||
final Block body,
|
||||
@ -338,6 +347,7 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
this.name = name;
|
||||
this.kind = kind;
|
||||
this.parameters = parameters;
|
||||
this.parameterExpressions = paramExprs;
|
||||
this.firstToken = firstToken;
|
||||
this.lastToken = lastToken;
|
||||
this.namespace = namespace;
|
||||
@ -375,6 +385,7 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
this.lastToken = lastToken;
|
||||
this.body = body;
|
||||
this.parameters = parameters;
|
||||
this.parameterExpressions = functionNode.parameterExpressions;
|
||||
this.thisProperties = thisProperties;
|
||||
this.rootClass = rootClass;
|
||||
this.source = source;
|
||||
@ -976,6 +987,15 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
return Collections.unmodifiableList(parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ES6 style parameter expressions of this function. This may be null.
|
||||
*
|
||||
* @return a Map of parameter IdentNode to Expression node (for ES6 parameter expressions)
|
||||
*/
|
||||
public Map<IdentNode, Expression> getParameterExpressions() {
|
||||
return parameterExpressions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of parameters to this function
|
||||
* @return the number of parameters
|
||||
|
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.internal.ir;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import jdk.nashorn.internal.codegen.types.Type;
|
||||
import jdk.nashorn.internal.ir.visitor.NodeVisitor;
|
||||
|
||||
/**
|
||||
* Represents ES6 template string expression. Note that this Node class is used
|
||||
* only in "parse only" mode. In evaluation mode, Parser directly folds template
|
||||
* literal as string concatenation. Parser API uses this node to represent ES6
|
||||
* template literals "as is" rather than as a String concatenation.
|
||||
*/
|
||||
public final class TemplateLiteral extends Expression {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final List<Expression> exprs;
|
||||
|
||||
public TemplateLiteral(final List<Expression> exprs) {
|
||||
super(exprs.get(0).getToken(), exprs.get(exprs.size() - 1).finish);
|
||||
this.exprs = exprs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getType() {
|
||||
return Type.STRING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Node accept(NodeVisitor<? extends LexicalContext> visitor) {
|
||||
if (visitor.enterTemplateLiteral(this)) {
|
||||
return visitor.leaveTemplateLiteral(this);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toString(StringBuilder sb, boolean printType) {
|
||||
for (Expression expr : exprs) {
|
||||
sb.append(expr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The list of expressions that are part of this template literal.
|
||||
*
|
||||
* @return the list of expressions that are part of this template literal.
|
||||
*/
|
||||
public List<Expression> getExpressions() {
|
||||
return Collections.unmodifiableList(exprs);
|
||||
}
|
||||
}
|
@ -59,6 +59,7 @@ import jdk.nashorn.internal.ir.SetSplitState;
|
||||
import jdk.nashorn.internal.ir.SplitNode;
|
||||
import jdk.nashorn.internal.ir.SplitReturn;
|
||||
import jdk.nashorn.internal.ir.SwitchNode;
|
||||
import jdk.nashorn.internal.ir.TemplateLiteral;
|
||||
import jdk.nashorn.internal.ir.TernaryNode;
|
||||
import jdk.nashorn.internal.ir.ThrowNode;
|
||||
import jdk.nashorn.internal.ir.TryNode;
|
||||
@ -737,6 +738,26 @@ public abstract class NodeVisitor<T extends LexicalContext> {
|
||||
return leaveDefault(switchNode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for entering a TemplateLiteral (used only in --parse-only mode)
|
||||
*
|
||||
* @param templateLiteral the node
|
||||
* @return true if traversal should continue and node children be traversed, false otherwise
|
||||
*/
|
||||
public boolean enterTemplateLiteral(final TemplateLiteral templateLiteral) {
|
||||
return enterDefault(templateLiteral);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for leaving a TemplateLiteral (used only in --parse-only mode)
|
||||
*
|
||||
* @param templateLiteral the node
|
||||
* @return processed node, which will replace the original one, or the original node
|
||||
*/
|
||||
public Node leaveTemplateLiteral(final TemplateLiteral templateLiteral) {
|
||||
return leaveDefault(templateLiteral);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for entering a TernaryNode
|
||||
*
|
||||
|
@ -127,6 +127,7 @@ import jdk.nashorn.internal.ir.ReturnNode;
|
||||
import jdk.nashorn.internal.ir.RuntimeNode;
|
||||
import jdk.nashorn.internal.ir.Statement;
|
||||
import jdk.nashorn.internal.ir.SwitchNode;
|
||||
import jdk.nashorn.internal.ir.TemplateLiteral;
|
||||
import jdk.nashorn.internal.ir.TernaryNode;
|
||||
import jdk.nashorn.internal.ir.ThrowNode;
|
||||
import jdk.nashorn.internal.ir.TryNode;
|
||||
@ -545,7 +546,7 @@ public class Parser extends AbstractParser implements Loggable {
|
||||
sb.append(ident.getName());
|
||||
|
||||
final String name = namespace.uniqueName(sb.toString());
|
||||
assert parentFunction != null || name.equals(PROGRAM.symbolName()) : "name = " + name;
|
||||
assert parentFunction != null || kind == FunctionNode.Kind.MODULE || name.equals(PROGRAM.symbolName()) : "name = " + name;
|
||||
|
||||
int flags = 0;
|
||||
if (isStrictMode) {
|
||||
@ -575,6 +576,7 @@ public class Parser extends AbstractParser implements Loggable {
|
||||
ident,
|
||||
function.getName(),
|
||||
parameters,
|
||||
function.getParameterExpressions(),
|
||||
kind,
|
||||
function.getFlags(),
|
||||
body,
|
||||
@ -622,19 +624,6 @@ public class Parser extends AbstractParser implements Loggable {
|
||||
return new Block(blockToken, finish, flags, newBlock.getStatements());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the statements in a case clause.
|
||||
*/
|
||||
private List<Statement> caseStatementList() {
|
||||
final ParserContextBlockNode newBlock = newBlock();
|
||||
try {
|
||||
statementList();
|
||||
} finally {
|
||||
restoreBlock(newBlock);
|
||||
}
|
||||
return newBlock.getStatements();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the statements generated by a single statement.
|
||||
* @return Statements.
|
||||
@ -855,17 +844,6 @@ public class Parser extends AbstractParser implements Loggable {
|
||||
});
|
||||
}
|
||||
|
||||
private static Expression newBinaryExpression(final long op, final Expression lhs, final Expression rhs) {
|
||||
final TokenType opType = Token.descType(op);
|
||||
|
||||
// Build up node.
|
||||
if (BinaryNode.isLogical(opType)) {
|
||||
return new BinaryNode(op, new JoinPredecessorExpression(lhs), new JoinPredecessorExpression(rhs));
|
||||
}
|
||||
return new BinaryNode(op, lhs, rhs);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reduce increment/decrement to simpler operations.
|
||||
* @param firstToken First token.
|
||||
@ -1268,7 +1246,7 @@ public class Parser extends AbstractParser implements Loggable {
|
||||
className = getIdent();
|
||||
}
|
||||
|
||||
return classTail(classLineNumber, classToken, className);
|
||||
return classTail(classLineNumber, classToken, className, isStatement);
|
||||
}
|
||||
|
||||
private static final class ClassElementKey {
|
||||
@ -1317,7 +1295,8 @@ public class Parser extends AbstractParser implements Loggable {
|
||||
* static MethodDefinition[?Yield]
|
||||
* ;
|
||||
*/
|
||||
private ClassNode classTail(final int classLineNumber, final long classToken, final IdentNode className) {
|
||||
private ClassNode classTail(final int classLineNumber, final long classToken,
|
||||
final IdentNode className, final boolean isStatement) {
|
||||
final boolean oldStrictMode = isStrictMode;
|
||||
isStrictMode = true;
|
||||
try {
|
||||
@ -1399,7 +1378,7 @@ public class Parser extends AbstractParser implements Loggable {
|
||||
}
|
||||
|
||||
classElements.trimToSize();
|
||||
return new ClassNode(classLineNumber, classToken, finish, className, classHeritage, constructor, classElements);
|
||||
return new ClassNode(classLineNumber, classToken, finish, className, classHeritage, constructor, classElements, isStatement);
|
||||
} finally {
|
||||
isStrictMode = oldStrictMode;
|
||||
}
|
||||
@ -1601,6 +1580,9 @@ public class Parser extends AbstractParser implements Loggable {
|
||||
private List<Expression> variableDeclarationList(final TokenType varType, final boolean isStatement, final int sourceOrder) {
|
||||
// VAR tested in caller.
|
||||
assert varType == VAR || varType == LET || varType == CONST;
|
||||
final int varLine = line;
|
||||
final long varToken = token;
|
||||
|
||||
next();
|
||||
|
||||
final List<Expression> bindings = new ArrayList<>();
|
||||
@ -1613,9 +1595,6 @@ public class Parser extends AbstractParser implements Loggable {
|
||||
|
||||
Expression missingAssignment = null;
|
||||
while (true) {
|
||||
// Get starting token.
|
||||
final int varLine = line;
|
||||
final long varToken = token;
|
||||
// Get name of var.
|
||||
if (type == YIELD && inGeneratorFunction()) {
|
||||
expect(IDENT);
|
||||
@ -1627,10 +1606,14 @@ public class Parser extends AbstractParser implements Loggable {
|
||||
if (isDestructuring) {
|
||||
final int finalVarFlags = varFlags;
|
||||
verifyDestructuringBindingPattern(binding, new Consumer<IdentNode>() {
|
||||
@Override
|
||||
public void accept(final IdentNode identNode) {
|
||||
verifyIdent(identNode, contextString);
|
||||
final VarNode var = new VarNode(varLine, varToken, sourceOrder, identNode.getFinish(), identNode.setIsDeclaredHere(), null, finalVarFlags);
|
||||
appendStatement(var);
|
||||
if (!env._parse_only) {
|
||||
// don't bother adding a variable if we are just parsing!
|
||||
final VarNode var = new VarNode(varLine, varToken, sourceOrder, identNode.getFinish(), identNode.setIsDeclaredHere(), null, finalVarFlags);
|
||||
appendStatement(var);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -1682,7 +1665,7 @@ public class Parser extends AbstractParser implements Loggable {
|
||||
assert init != null || !isStatement;
|
||||
binding = init == null ? binding : verifyAssignment(Token.recast(varToken, ASSIGN), binding, init);
|
||||
if (isStatement) {
|
||||
appendStatement(new ExpressionStatement(varLine, binding.getToken(), finish, binding));
|
||||
appendStatement(new ExpressionStatement(varLine, binding.getToken(), finish, binding, varType));
|
||||
} else if (init == null) {
|
||||
if (missingAssignment == null) {
|
||||
missingAssignment = binding;
|
||||
@ -1748,7 +1731,8 @@ public class Parser extends AbstractParser implements Loggable {
|
||||
* Verify destructuring variable declaration binding pattern and extract bound variable declarations.
|
||||
*/
|
||||
private void verifyDestructuringBindingPattern(final Expression pattern, final Consumer<IdentNode> identifierCallback) {
|
||||
assert pattern instanceof ObjectNode || pattern instanceof LiteralNode.ArrayLiteralNode;
|
||||
assert (pattern instanceof BinaryNode && ((BinaryNode)pattern).isTokenType(ASSIGN)) ||
|
||||
pattern instanceof ObjectNode || pattern instanceof LiteralNode.ArrayLiteralNode;
|
||||
pattern.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
|
||||
@Override
|
||||
public boolean enterLiteralNode(final LiteralNode<?> literalNode) {
|
||||
@ -1857,9 +1841,8 @@ public class Parser extends AbstractParser implements Loggable {
|
||||
// Get expression and add as statement.
|
||||
final Expression expression = expression();
|
||||
|
||||
ExpressionStatement expressionStatement = null;
|
||||
if (expression != null) {
|
||||
expressionStatement = new ExpressionStatement(expressionLine, expressionToken, finish, expression);
|
||||
ExpressionStatement expressionStatement = new ExpressionStatement(expressionLine, expressionToken, finish, expression);
|
||||
appendStatement(expressionStatement);
|
||||
} else {
|
||||
expect(null);
|
||||
@ -2625,6 +2608,10 @@ public class Parser extends AbstractParser implements Loggable {
|
||||
final long catchToken = token;
|
||||
next();
|
||||
expect(LPAREN);
|
||||
|
||||
// FIXME: ES6 catch parameter can be a BindingIdentifier or a BindingPattern
|
||||
// We need to generalize this here!
|
||||
// http://www.ecma-international.org/ecma-262/6.0/
|
||||
final IdentNode exception = getIdent();
|
||||
|
||||
// ECMA 12.4.1 strict mode restrictions
|
||||
@ -4021,12 +4008,18 @@ public class Parser extends AbstractParser implements Loggable {
|
||||
|
||||
ParserContextFunctionNode currentFunction = lc.getCurrentFunction();
|
||||
if (currentFunction != null) {
|
||||
// desugar to: param = (param === undefined) ? initializer : param;
|
||||
// possible alternative: if (param === undefined) param = initializer;
|
||||
BinaryNode test = new BinaryNode(Token.recast(paramToken, EQ_STRICT), ident, newUndefinedLiteral(paramToken, finish));
|
||||
TernaryNode value = new TernaryNode(Token.recast(paramToken, TERNARY), test, new JoinPredecessorExpression(initializer), new JoinPredecessorExpression(ident));
|
||||
BinaryNode assignment = new BinaryNode(Token.recast(paramToken, ASSIGN), ident, value);
|
||||
lc.getFunctionBody(currentFunction).appendStatement(new ExpressionStatement(paramLine, assignment.getToken(), assignment.getFinish(), assignment));
|
||||
if (env._parse_only) {
|
||||
// keep what is seen in source "as is" and save it as parameter expression
|
||||
BinaryNode assignment = new BinaryNode(Token.recast(paramToken, ASSIGN), ident, initializer);
|
||||
currentFunction.addParameterExpression(ident, assignment);
|
||||
} else {
|
||||
// desugar to: param = (param === undefined) ? initializer : param;
|
||||
// possible alternative: if (param === undefined) param = initializer;
|
||||
BinaryNode test = new BinaryNode(Token.recast(paramToken, EQ_STRICT), ident, newUndefinedLiteral(paramToken, finish));
|
||||
TernaryNode value = new TernaryNode(Token.recast(paramToken, TERNARY), test, new JoinPredecessorExpression(initializer), new JoinPredecessorExpression(ident));
|
||||
BinaryNode assignment = new BinaryNode(Token.recast(paramToken, ASSIGN), ident, value);
|
||||
lc.getFunctionBody(currentFunction).appendStatement(new ExpressionStatement(paramLine, assignment.getToken(), assignment.getFinish(), assignment));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -4050,16 +4043,31 @@ public class Parser extends AbstractParser implements Loggable {
|
||||
|
||||
// binding pattern with initializer. desugar to: (param === undefined) ? initializer : param
|
||||
Expression initializer = assignmentExpression(false);
|
||||
// TODO initializer must not contain yield expression if yield=true (i.e. this is generator function's parameter list)
|
||||
BinaryNode test = new BinaryNode(Token.recast(paramToken, EQ_STRICT), ident, newUndefinedLiteral(paramToken, finish));
|
||||
value = new TernaryNode(Token.recast(paramToken, TERNARY), test, new JoinPredecessorExpression(initializer), new JoinPredecessorExpression(ident));
|
||||
|
||||
if (env._parse_only) {
|
||||
// we don't want the synthetic identifier in parse only mode
|
||||
value = initializer;
|
||||
} else {
|
||||
// TODO initializer must not contain yield expression if yield=true (i.e. this is generator function's parameter list)
|
||||
BinaryNode test = new BinaryNode(Token.recast(paramToken, EQ_STRICT), ident, newUndefinedLiteral(paramToken, finish));
|
||||
value = new TernaryNode(Token.recast(paramToken, TERNARY), test, new JoinPredecessorExpression(initializer), new JoinPredecessorExpression(ident));
|
||||
}
|
||||
}
|
||||
|
||||
ParserContextFunctionNode currentFunction = lc.getCurrentFunction();
|
||||
if (currentFunction != null) {
|
||||
// destructuring assignment
|
||||
BinaryNode assignment = new BinaryNode(Token.recast(paramToken, ASSIGN), pattern, value);
|
||||
lc.getFunctionBody(currentFunction).appendStatement(new ExpressionStatement(paramLine, assignment.getToken(), assignment.getFinish(), assignment));
|
||||
if (env._parse_only) {
|
||||
// in parse-only mode, represent source tree "as is"
|
||||
if (ident.isDefaultParameter()) {
|
||||
currentFunction.addParameterExpression(ident, assignment);
|
||||
} else {
|
||||
currentFunction.addParameterExpression(ident, pattern);
|
||||
}
|
||||
} else {
|
||||
lc.getFunctionBody(currentFunction).appendStatement(new ExpressionStatement(paramLine, assignment.getToken(), assignment.getFinish(), assignment));
|
||||
}
|
||||
}
|
||||
}
|
||||
parameters.add(ident);
|
||||
@ -4077,7 +4085,9 @@ public class Parser extends AbstractParser implements Loggable {
|
||||
ParserContextFunctionNode currentFunction = lc.getCurrentFunction();
|
||||
if (currentFunction != null) {
|
||||
// declare function-scope variables for destructuring bindings
|
||||
lc.getFunctionBody(currentFunction).appendStatement(new VarNode(paramLine, Token.recast(paramToken, VAR), pattern.getFinish(), identNode, null));
|
||||
if (!env._parse_only) {
|
||||
lc.getFunctionBody(currentFunction).appendStatement(new VarNode(paramLine, Token.recast(paramToken, VAR), pattern.getFinish(), identNode, null));
|
||||
}
|
||||
// detect duplicate bounds names in parameter list
|
||||
currentFunction.addParameterBinding(identNode);
|
||||
currentFunction.setSimpleParameterList(false);
|
||||
@ -4136,6 +4146,7 @@ public class Parser extends AbstractParser implements Loggable {
|
||||
// the note below for reasoning on skipping happening before instead of after RBRACE for
|
||||
// details).
|
||||
if (parseBody) {
|
||||
functionNode.setFlag(FunctionNode.HAS_EXPRESSION_BODY);
|
||||
final ReturnNode returnNode = new ReturnNode(functionNode.getLineNumber(), expr.getToken(), lastFinish, expr);
|
||||
appendStatement(returnNode);
|
||||
}
|
||||
@ -4305,7 +4316,7 @@ public class Parser extends AbstractParser implements Loggable {
|
||||
}
|
||||
|
||||
private RuntimeNode referenceError(final Expression lhs, final Expression rhs, final boolean earlyError) {
|
||||
if (earlyError) {
|
||||
if (env._parse_only || earlyError) {
|
||||
throw error(JSErrorType.REFERENCE_ERROR, AbstractParser.message("invalid.lvalue"), lhs.getToken());
|
||||
}
|
||||
final ArrayList<Expression> args = new ArrayList<>();
|
||||
@ -4838,10 +4849,14 @@ public class Parser extends AbstractParser implements Loggable {
|
||||
|
||||
ParserContextFunctionNode currentFunction = lc.getCurrentFunction();
|
||||
if (currentFunction != null) {
|
||||
BinaryNode test = new BinaryNode(Token.recast(paramToken, EQ_STRICT), ident, newUndefinedLiteral(paramToken, finish));
|
||||
TernaryNode value = new TernaryNode(Token.recast(paramToken, TERNARY), test, new JoinPredecessorExpression(initializer), new JoinPredecessorExpression(ident));
|
||||
BinaryNode assignment = new BinaryNode(Token.recast(paramToken, ASSIGN), ident, value);
|
||||
lc.getFunctionBody(currentFunction).appendStatement(new ExpressionStatement(paramLine, assignment.getToken(), assignment.getFinish(), assignment));
|
||||
if (env._parse_only) {
|
||||
currentFunction.addParameterExpression(ident, param);
|
||||
} else {
|
||||
BinaryNode test = new BinaryNode(Token.recast(paramToken, EQ_STRICT), ident, newUndefinedLiteral(paramToken, finish));
|
||||
TernaryNode value = new TernaryNode(Token.recast(paramToken, TERNARY), test, new JoinPredecessorExpression(initializer), new JoinPredecessorExpression(ident));
|
||||
BinaryNode assignment = new BinaryNode(Token.recast(paramToken, ASSIGN), ident, value);
|
||||
lc.getFunctionBody(currentFunction).appendStatement(new ExpressionStatement(paramLine, assignment.getToken(), assignment.getFinish(), assignment));
|
||||
}
|
||||
|
||||
currentFunction.addParameterBinding(ident);
|
||||
currentFunction.setSimpleParameterList(false);
|
||||
@ -4855,10 +4870,14 @@ public class Parser extends AbstractParser implements Loggable {
|
||||
|
||||
ParserContextFunctionNode currentFunction = lc.getCurrentFunction();
|
||||
if (currentFunction != null) {
|
||||
BinaryNode test = new BinaryNode(Token.recast(paramToken, EQ_STRICT), ident, newUndefinedLiteral(paramToken, finish));
|
||||
TernaryNode value = new TernaryNode(Token.recast(paramToken, TERNARY), test, new JoinPredecessorExpression(initializer), new JoinPredecessorExpression(ident));
|
||||
BinaryNode assignment = new BinaryNode(Token.recast(paramToken, ASSIGN), param, value);
|
||||
lc.getFunctionBody(currentFunction).appendStatement(new ExpressionStatement(paramLine, assignment.getToken(), assignment.getFinish(), assignment));
|
||||
if (env._parse_only) {
|
||||
currentFunction.addParameterExpression(ident, param);
|
||||
} else {
|
||||
BinaryNode test = new BinaryNode(Token.recast(paramToken, EQ_STRICT), ident, newUndefinedLiteral(paramToken, finish));
|
||||
TernaryNode value = new TernaryNode(Token.recast(paramToken, TERNARY), test, new JoinPredecessorExpression(initializer), new JoinPredecessorExpression(ident));
|
||||
BinaryNode assignment = new BinaryNode(Token.recast(paramToken, ASSIGN), param, value);
|
||||
lc.getFunctionBody(currentFunction).appendStatement(new ExpressionStatement(paramLine, assignment.getToken(), assignment.getFinish(), assignment));
|
||||
}
|
||||
}
|
||||
return ident;
|
||||
}
|
||||
@ -4872,8 +4891,12 @@ public class Parser extends AbstractParser implements Loggable {
|
||||
|
||||
ParserContextFunctionNode currentFunction = lc.getCurrentFunction();
|
||||
if (currentFunction != null) {
|
||||
BinaryNode assignment = new BinaryNode(Token.recast(paramToken, ASSIGN), param, ident);
|
||||
lc.getFunctionBody(currentFunction).appendStatement(new ExpressionStatement(paramLine, assignment.getToken(), assignment.getFinish(), assignment));
|
||||
if (env._parse_only) {
|
||||
currentFunction.addParameterExpression(ident, param);
|
||||
} else {
|
||||
BinaryNode assignment = new BinaryNode(Token.recast(paramToken, ASSIGN), param, ident);
|
||||
lc.getFunctionBody(currentFunction).appendStatement(new ExpressionStatement(paramLine, assignment.getToken(), assignment.getFinish(), assignment));
|
||||
}
|
||||
}
|
||||
return ident;
|
||||
}
|
||||
@ -4982,20 +5005,37 @@ public class Parser extends AbstractParser implements Loggable {
|
||||
return literal;
|
||||
}
|
||||
|
||||
Expression concat = literal;
|
||||
TokenType lastLiteralType;
|
||||
do {
|
||||
final Expression expression = expression();
|
||||
if (type != TEMPLATE_MIDDLE && type != TEMPLATE_TAIL) {
|
||||
throw error(AbstractParser.message("unterminated.template.expression"), token);
|
||||
}
|
||||
concat = new BinaryNode(Token.recast(lastLiteralToken, TokenType.ADD), concat, expression);
|
||||
lastLiteralType = type;
|
||||
lastLiteralToken = token;
|
||||
literal = getLiteral();
|
||||
concat = new BinaryNode(Token.recast(lastLiteralToken, TokenType.ADD), concat, literal);
|
||||
} while (lastLiteralType == TEMPLATE_MIDDLE);
|
||||
return concat;
|
||||
if (env._parse_only) {
|
||||
List<Expression> exprs = new ArrayList<>();
|
||||
exprs.add(literal);
|
||||
TokenType lastLiteralType;
|
||||
do {
|
||||
final Expression expression = expression();
|
||||
if (type != TEMPLATE_MIDDLE && type != TEMPLATE_TAIL) {
|
||||
throw error(AbstractParser.message("unterminated.template.expression"), token);
|
||||
}
|
||||
exprs.add(expression);
|
||||
lastLiteralType = type;
|
||||
literal = getLiteral();
|
||||
exprs.add(literal);
|
||||
} while (lastLiteralType == TEMPLATE_MIDDLE);
|
||||
return new TemplateLiteral(exprs);
|
||||
} else {
|
||||
Expression concat = literal;
|
||||
TokenType lastLiteralType;
|
||||
do {
|
||||
final Expression expression = expression();
|
||||
if (type != TEMPLATE_MIDDLE && type != TEMPLATE_TAIL) {
|
||||
throw error(AbstractParser.message("unterminated.template.expression"), token);
|
||||
}
|
||||
concat = new BinaryNode(Token.recast(lastLiteralToken, TokenType.ADD), concat, expression);
|
||||
lastLiteralType = type;
|
||||
lastLiteralToken = token;
|
||||
literal = getLiteral();
|
||||
concat = new BinaryNode(Token.recast(lastLiteralToken, TokenType.ADD), concat, literal);
|
||||
} while (lastLiteralType == TEMPLATE_MIDDLE);
|
||||
return concat;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -24,9 +24,12 @@
|
||||
*/
|
||||
package jdk.nashorn.internal.parser;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import jdk.nashorn.internal.codegen.Namespace;
|
||||
import jdk.nashorn.internal.ir.Expression;
|
||||
import jdk.nashorn.internal.ir.FunctionNode;
|
||||
import jdk.nashorn.internal.ir.IdentNode;
|
||||
import jdk.nashorn.internal.ir.Module;
|
||||
@ -70,6 +73,7 @@ class ParserContextFunctionNode extends ParserContextBaseNode {
|
||||
private Module module;
|
||||
|
||||
private int debugFlags;
|
||||
private Map<IdentNode, Expression> parameterExpressions;
|
||||
|
||||
/**
|
||||
* @param token The token for the function
|
||||
@ -169,6 +173,22 @@ class ParserContextFunctionNode extends ParserContextBaseNode {
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return ES6 function parameter expressions
|
||||
*
|
||||
* @return ES6 function parameter expressions
|
||||
*/
|
||||
public Map<IdentNode, Expression> getParameterExpressions() {
|
||||
return parameterExpressions;
|
||||
}
|
||||
|
||||
void addParameterExpression(IdentNode ident, Expression node) {
|
||||
if (parameterExpressions == null) {
|
||||
parameterExpressions = new HashMap<>();
|
||||
}
|
||||
parameterExpressions.put(ident, node);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set last token
|
||||
* @param token New last token
|
||||
|
@ -61,7 +61,7 @@ Assert.assertTrue(stats.get(1) instanceof FunctionDeclarationTree);
|
||||
Assert.assertTrue(stats.get(2) instanceof VariableTree);
|
||||
|
||||
var print_hello = stats.get(1);
|
||||
Assert.assertEquals(print_hello.name, "print_hello");
|
||||
Assert.assertEquals(print_hello.name.name, "print_hello");
|
||||
var print_hello_stats = print_hello.body.statements;
|
||||
Assert.assertTrue(print_hello_stats.get(0) instanceof VariableTree);
|
||||
Assert.assertTrue(print_hello_stats.get(1) instanceof ExpressionStatementTree);
|
||||
|
@ -44,6 +44,6 @@ var ast = parser.parse("test.js", code, print);
|
||||
var stats = ast.sourceElements;
|
||||
|
||||
Assert.assertTrue(stats[0] instanceof VariableTree);
|
||||
Assert.assertEquals(stats[0].name, "i");
|
||||
Assert.assertEquals(stats[0].binding.name, "i");
|
||||
Assert.assertTrue(stats[1] instanceof ForLoopTree);
|
||||
|
||||
|
@ -1,12 +1,12 @@
|
||||
1
|
||||
2
|
||||
0
|
||||
1
|
||||
2
|
||||
0
|
||||
SyntaxError: test/script/basic/es6/let-const-switch.js#34:8<eval>:1:25 Unsupported let declaration in unprotected switch statement
|
||||
switch (x) { case 0: let x = 1; }
|
||||
^
|
||||
SyntaxError: test/script/basic/es6/let-const-switch.js#34:8<eval>:1:27 Unsupported const declaration in unprotected switch statement
|
||||
switch (x) { case 0: const x = 1; }
|
||||
^
|
||||
1
|
||||
2
|
||||
0
|
||||
1
|
||||
2
|
||||
0
|
||||
SyntaxError: test/script/basic/es6/let-const-switch.js#34:8<eval>:1:21 Unsupported let declaration in unprotected switch statement
|
||||
switch (x) { case 0: let x = 1; }
|
||||
^
|
||||
SyntaxError: test/script/basic/es6/let-const-switch.js#34:8<eval>:1:21 Unsupported const declaration in unprotected switch statement
|
||||
switch (x) { case 0: const x = 1; }
|
||||
^
|
||||
|
@ -62,6 +62,26 @@ Parser.prototype.convert = function(tree) {
|
||||
var result = {};
|
||||
for (var i in obj) {
|
||||
var val = obj[i];
|
||||
// skip these ES6 specific properties to reduce noise
|
||||
// in the output - unless there were set to true
|
||||
if (typeof(val) == 'boolean' && val == false) {
|
||||
switch (i) {
|
||||
case "computed":
|
||||
case "static":
|
||||
case "restParameter":
|
||||
case "this":
|
||||
case "super":
|
||||
case "star":
|
||||
case "default":
|
||||
case "starDefaultStar":
|
||||
case "arrow":
|
||||
case "generator":
|
||||
case "let":
|
||||
case "const":
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (val instanceof Parser.Tree) {
|
||||
result[i] = this.convert(val);
|
||||
} else if (val instanceof Parser.List) {
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -202,7 +202,7 @@ parse("funccall.js", "func()",
|
||||
parse("funcdecl.js", "function func() {}",
|
||||
new (Java.extend(SimpleTreeVisitor))() {
|
||||
visitFunctionDeclaration: function(fd) {
|
||||
print("in visitFunctionDeclaration " + fd.name);
|
||||
print("in visitFunctionDeclaration " + fd.name.name);
|
||||
}
|
||||
});
|
||||
|
||||
@ -361,7 +361,7 @@ unaryExpr("void.js", "void x");
|
||||
parse("var.js", "var x = 34;",
|
||||
new (Java.extend(SimpleTreeVisitor))() {
|
||||
visitVariable: function(vn) {
|
||||
print("in visitVariable " + vn.name + " = " + vn.initializer.value);
|
||||
print("in visitVariable " + vn.binding.name + " = " + vn.initializer.value);
|
||||
}
|
||||
});
|
||||
|
||||
|
49
nashorn/test/script/nosecurity/treeapi/arrow.js
Normal file
49
nashorn/test/script/nosecurity/treeapi/arrow.js
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests to check representation of ES6 arrows.
|
||||
*
|
||||
* @test
|
||||
* @option -scripting
|
||||
* @run
|
||||
*/
|
||||
|
||||
load(__DIR__ + "utils.js")
|
||||
|
||||
var code = <<EOF
|
||||
|
||||
var f = x=>x*2;
|
||||
[].map(v => v + 1);
|
||||
|
||||
EOF
|
||||
|
||||
parse("arrow.js", code, "--language=es6", new (Java.extend(visitor_es6, {
|
||||
visitVariable : function (node, obj) {
|
||||
obj.push(convert(node))
|
||||
},
|
||||
visitExpressionStatement : function (node, obj) {
|
||||
obj.push(convert(node))
|
||||
}
|
||||
})))
|
||||
|
103
nashorn/test/script/nosecurity/treeapi/arrow.js.EXPECTED
Normal file
103
nashorn/test/script/nosecurity/treeapi/arrow.js.EXPECTED
Normal file
@ -0,0 +1,103 @@
|
||||
[
|
||||
{
|
||||
"endPosition": "15",
|
||||
"kind": "VARIABLE",
|
||||
"binding": {
|
||||
"endPosition": "6",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "f",
|
||||
"startPosition": "5"
|
||||
},
|
||||
"startPosition": "1",
|
||||
"initializer": {
|
||||
"endPosition": "12",
|
||||
"arrow": "true",
|
||||
"kind": "FUNCTION_EXPRESSION",
|
||||
"name": "null",
|
||||
"body": {
|
||||
"leftOperand": {
|
||||
"endPosition": "13",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "x",
|
||||
"startPosition": "12"
|
||||
},
|
||||
"endPosition": "15",
|
||||
"kind": "MULTIPLY",
|
||||
"rightOperand": {
|
||||
"endPosition": "15",
|
||||
"kind": "NUMBER_LITERAL",
|
||||
"value": "2",
|
||||
"startPosition": "14"
|
||||
},
|
||||
"startPosition": "12"
|
||||
},
|
||||
"strict": "false",
|
||||
"startPosition": "12",
|
||||
"parameters": [
|
||||
{
|
||||
"endPosition": "10",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "x",
|
||||
"startPosition": "9"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"expression": {
|
||||
"endPosition": "35",
|
||||
"kind": "FUNCTION_INVOCATION",
|
||||
"functionSelect": {
|
||||
"identifier": "map",
|
||||
"expression": {
|
||||
"endPosition": "19",
|
||||
"kind": "ARRAY_LITERAL",
|
||||
"elements": [],
|
||||
"startPosition": "17"
|
||||
},
|
||||
"endPosition": "23",
|
||||
"kind": "MEMBER_SELECT",
|
||||
"startPosition": "17"
|
||||
},
|
||||
"arguments": [
|
||||
{
|
||||
"endPosition": "29",
|
||||
"arrow": "true",
|
||||
"kind": "FUNCTION_EXPRESSION",
|
||||
"name": "null",
|
||||
"body": {
|
||||
"leftOperand": {
|
||||
"endPosition": "30",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "v",
|
||||
"startPosition": "29"
|
||||
},
|
||||
"endPosition": "34",
|
||||
"kind": "PLUS",
|
||||
"rightOperand": {
|
||||
"endPosition": "34",
|
||||
"kind": "NUMBER_LITERAL",
|
||||
"value": "1",
|
||||
"startPosition": "33"
|
||||
},
|
||||
"startPosition": "29"
|
||||
},
|
||||
"strict": "false",
|
||||
"startPosition": "29",
|
||||
"parameters": [
|
||||
{
|
||||
"endPosition": "25",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "v",
|
||||
"startPosition": "24"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"startPosition": "17"
|
||||
},
|
||||
"endPosition": "35",
|
||||
"kind": "EXPRESSION_STATEMENT",
|
||||
"startPosition": "17"
|
||||
}
|
||||
]
|
49
nashorn/test/script/nosecurity/treeapi/arrow_params.js
Normal file
49
nashorn/test/script/nosecurity/treeapi/arrow_params.js
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests to check representation of ES6 arrow params.
|
||||
*
|
||||
* @test
|
||||
* @option -scripting
|
||||
* @run
|
||||
*/
|
||||
|
||||
load(__DIR__ + "utils.js")
|
||||
|
||||
var code = <<EOF
|
||||
|
||||
var f1 = (x=2)=>x*3;
|
||||
var f2 = ({x, y})=>x*y;
|
||||
var f3 = ([x, y])=>x+y;
|
||||
var f4 = ({x, y}={y: 4, x: 5})=>x*y;
|
||||
var f5 = ([x, y]=[3, 6])=>x+y;
|
||||
|
||||
EOF
|
||||
|
||||
parse("arrow_params.js", code, "--language=es6", new (Java.extend(visitor_es6, {
|
||||
visitVariable : function (node, obj) {
|
||||
obj.push(convert(node))
|
||||
}
|
||||
})))
|
||||
|
411
nashorn/test/script/nosecurity/treeapi/arrow_params.js.EXPECTED
Normal file
411
nashorn/test/script/nosecurity/treeapi/arrow_params.js.EXPECTED
Normal file
@ -0,0 +1,411 @@
|
||||
[
|
||||
{
|
||||
"endPosition": "20",
|
||||
"kind": "VARIABLE",
|
||||
"binding": {
|
||||
"endPosition": "7",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "f1",
|
||||
"startPosition": "5"
|
||||
},
|
||||
"startPosition": "1",
|
||||
"initializer": {
|
||||
"endPosition": "17",
|
||||
"arrow": "true",
|
||||
"kind": "FUNCTION_EXPRESSION",
|
||||
"name": "null",
|
||||
"body": {
|
||||
"leftOperand": {
|
||||
"endPosition": "18",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "x",
|
||||
"startPosition": "17"
|
||||
},
|
||||
"endPosition": "20",
|
||||
"kind": "MULTIPLY",
|
||||
"rightOperand": {
|
||||
"endPosition": "20",
|
||||
"kind": "NUMBER_LITERAL",
|
||||
"value": "3",
|
||||
"startPosition": "19"
|
||||
},
|
||||
"startPosition": "17"
|
||||
},
|
||||
"strict": "false",
|
||||
"startPosition": "17",
|
||||
"parameters": [
|
||||
{
|
||||
"expression": {
|
||||
"endPosition": "14",
|
||||
"kind": "NUMBER_LITERAL",
|
||||
"value": "2",
|
||||
"startPosition": "13"
|
||||
},
|
||||
"endPosition": "14",
|
||||
"kind": "ASSIGNMENT",
|
||||
"variable": {
|
||||
"endPosition": "12",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "x",
|
||||
"startPosition": "11"
|
||||
},
|
||||
"startPosition": "11"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"endPosition": "44",
|
||||
"kind": "VARIABLE",
|
||||
"binding": {
|
||||
"endPosition": "28",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "f2",
|
||||
"startPosition": "26"
|
||||
},
|
||||
"startPosition": "22",
|
||||
"initializer": {
|
||||
"endPosition": "41",
|
||||
"arrow": "true",
|
||||
"kind": "FUNCTION_EXPRESSION",
|
||||
"name": "null",
|
||||
"body": {
|
||||
"leftOperand": {
|
||||
"endPosition": "42",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "x",
|
||||
"startPosition": "41"
|
||||
},
|
||||
"endPosition": "44",
|
||||
"kind": "MULTIPLY",
|
||||
"rightOperand": {
|
||||
"endPosition": "44",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "y",
|
||||
"startPosition": "43"
|
||||
},
|
||||
"startPosition": "41"
|
||||
},
|
||||
"strict": "false",
|
||||
"startPosition": "41",
|
||||
"parameters": [
|
||||
{
|
||||
"endPosition": "38",
|
||||
"kind": "OBJECT_LITERAL",
|
||||
"startPosition": "32",
|
||||
"properties": [
|
||||
{
|
||||
"getter": "null",
|
||||
"endPosition": "34",
|
||||
"kind": "PROPERTY",
|
||||
"setter": "null",
|
||||
"value": {
|
||||
"endPosition": "34",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "x",
|
||||
"startPosition": "33"
|
||||
},
|
||||
"startPosition": "33",
|
||||
"key": {
|
||||
"endPosition": "34",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "x",
|
||||
"startPosition": "33"
|
||||
}
|
||||
},
|
||||
{
|
||||
"getter": "null",
|
||||
"endPosition": "37",
|
||||
"kind": "PROPERTY",
|
||||
"setter": "null",
|
||||
"value": {
|
||||
"endPosition": "37",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "y",
|
||||
"startPosition": "36"
|
||||
},
|
||||
"startPosition": "36",
|
||||
"key": {
|
||||
"endPosition": "37",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "y",
|
||||
"startPosition": "36"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"endPosition": "68",
|
||||
"kind": "VARIABLE",
|
||||
"binding": {
|
||||
"endPosition": "52",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "f3",
|
||||
"startPosition": "50"
|
||||
},
|
||||
"startPosition": "46",
|
||||
"initializer": {
|
||||
"endPosition": "65",
|
||||
"arrow": "true",
|
||||
"kind": "FUNCTION_EXPRESSION",
|
||||
"name": "null",
|
||||
"body": {
|
||||
"leftOperand": {
|
||||
"endPosition": "66",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "x",
|
||||
"startPosition": "65"
|
||||
},
|
||||
"endPosition": "68",
|
||||
"kind": "PLUS",
|
||||
"rightOperand": {
|
||||
"endPosition": "68",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "y",
|
||||
"startPosition": "67"
|
||||
},
|
||||
"startPosition": "65"
|
||||
},
|
||||
"strict": "false",
|
||||
"startPosition": "65",
|
||||
"parameters": [
|
||||
{
|
||||
"endPosition": "62",
|
||||
"kind": "ARRAY_LITERAL",
|
||||
"elements": [
|
||||
{
|
||||
"endPosition": "58",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "x",
|
||||
"startPosition": "57"
|
||||
},
|
||||
{
|
||||
"endPosition": "61",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "y",
|
||||
"startPosition": "60"
|
||||
}
|
||||
],
|
||||
"startPosition": "56"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"endPosition": "105",
|
||||
"kind": "VARIABLE",
|
||||
"binding": {
|
||||
"endPosition": "76",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "f4",
|
||||
"startPosition": "74"
|
||||
},
|
||||
"startPosition": "70",
|
||||
"initializer": {
|
||||
"endPosition": "102",
|
||||
"arrow": "true",
|
||||
"kind": "FUNCTION_EXPRESSION",
|
||||
"name": "null",
|
||||
"body": {
|
||||
"leftOperand": {
|
||||
"endPosition": "103",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "x",
|
||||
"startPosition": "102"
|
||||
},
|
||||
"endPosition": "105",
|
||||
"kind": "MULTIPLY",
|
||||
"rightOperand": {
|
||||
"endPosition": "105",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "y",
|
||||
"startPosition": "104"
|
||||
},
|
||||
"startPosition": "102"
|
||||
},
|
||||
"strict": "false",
|
||||
"startPosition": "102",
|
||||
"parameters": [
|
||||
{
|
||||
"expression": {
|
||||
"endPosition": "99",
|
||||
"kind": "OBJECT_LITERAL",
|
||||
"startPosition": "87",
|
||||
"properties": [
|
||||
{
|
||||
"getter": "null",
|
||||
"endPosition": "92",
|
||||
"kind": "PROPERTY",
|
||||
"setter": "null",
|
||||
"value": {
|
||||
"endPosition": "92",
|
||||
"kind": "NUMBER_LITERAL",
|
||||
"value": "4",
|
||||
"startPosition": "91"
|
||||
},
|
||||
"startPosition": "88",
|
||||
"key": {
|
||||
"endPosition": "89",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "y",
|
||||
"startPosition": "88"
|
||||
}
|
||||
},
|
||||
{
|
||||
"getter": "null",
|
||||
"endPosition": "98",
|
||||
"kind": "PROPERTY",
|
||||
"setter": "null",
|
||||
"value": {
|
||||
"endPosition": "98",
|
||||
"kind": "NUMBER_LITERAL",
|
||||
"value": "5",
|
||||
"startPosition": "97"
|
||||
},
|
||||
"startPosition": "94",
|
||||
"key": {
|
||||
"endPosition": "95",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "x",
|
||||
"startPosition": "94"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"endPosition": "99",
|
||||
"kind": "ASSIGNMENT",
|
||||
"variable": {
|
||||
"endPosition": "86",
|
||||
"kind": "OBJECT_LITERAL",
|
||||
"startPosition": "80",
|
||||
"properties": [
|
||||
{
|
||||
"getter": "null",
|
||||
"endPosition": "82",
|
||||
"kind": "PROPERTY",
|
||||
"setter": "null",
|
||||
"value": {
|
||||
"endPosition": "82",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "x",
|
||||
"startPosition": "81"
|
||||
},
|
||||
"startPosition": "81",
|
||||
"key": {
|
||||
"endPosition": "82",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "x",
|
||||
"startPosition": "81"
|
||||
}
|
||||
},
|
||||
{
|
||||
"getter": "null",
|
||||
"endPosition": "85",
|
||||
"kind": "PROPERTY",
|
||||
"setter": "null",
|
||||
"value": {
|
||||
"endPosition": "85",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "y",
|
||||
"startPosition": "84"
|
||||
},
|
||||
"startPosition": "84",
|
||||
"key": {
|
||||
"endPosition": "85",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "y",
|
||||
"startPosition": "84"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"startPosition": "80"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"endPosition": "136",
|
||||
"kind": "VARIABLE",
|
||||
"binding": {
|
||||
"endPosition": "113",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "f5",
|
||||
"startPosition": "111"
|
||||
},
|
||||
"startPosition": "107",
|
||||
"initializer": {
|
||||
"endPosition": "133",
|
||||
"arrow": "true",
|
||||
"kind": "FUNCTION_EXPRESSION",
|
||||
"name": "null",
|
||||
"body": {
|
||||
"leftOperand": {
|
||||
"endPosition": "134",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "x",
|
||||
"startPosition": "133"
|
||||
},
|
||||
"endPosition": "136",
|
||||
"kind": "PLUS",
|
||||
"rightOperand": {
|
||||
"endPosition": "136",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "y",
|
||||
"startPosition": "135"
|
||||
},
|
||||
"startPosition": "133"
|
||||
},
|
||||
"strict": "false",
|
||||
"startPosition": "133",
|
||||
"parameters": [
|
||||
{
|
||||
"expression": {
|
||||
"endPosition": "130",
|
||||
"kind": "ARRAY_LITERAL",
|
||||
"elements": [
|
||||
{
|
||||
"endPosition": "126",
|
||||
"kind": "NUMBER_LITERAL",
|
||||
"value": "3",
|
||||
"startPosition": "125"
|
||||
},
|
||||
{
|
||||
"endPosition": "129",
|
||||
"kind": "NUMBER_LITERAL",
|
||||
"value": "6",
|
||||
"startPosition": "128"
|
||||
}
|
||||
],
|
||||
"startPosition": "124"
|
||||
},
|
||||
"endPosition": "130",
|
||||
"kind": "ASSIGNMENT",
|
||||
"variable": {
|
||||
"endPosition": "123",
|
||||
"kind": "ARRAY_LITERAL",
|
||||
"elements": [
|
||||
{
|
||||
"endPosition": "119",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "x",
|
||||
"startPosition": "118"
|
||||
},
|
||||
{
|
||||
"endPosition": "122",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "y",
|
||||
"startPosition": "121"
|
||||
}
|
||||
],
|
||||
"startPosition": "117"
|
||||
},
|
||||
"startPosition": "117"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
@ -146,4 +146,4 @@
|
||||
},
|
||||
"startPosition": "61"
|
||||
}
|
||||
]
|
||||
]
|
||||
|
91
nashorn/test/script/nosecurity/treeapi/class.js
Normal file
91
nashorn/test/script/nosecurity/treeapi/class.js
Normal file
@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests to check representation of ES6 class.
|
||||
*
|
||||
* @test
|
||||
* @option -scripting
|
||||
* @run
|
||||
*/
|
||||
|
||||
load(__DIR__ + "utils.js")
|
||||
|
||||
var code = <<EOF
|
||||
|
||||
class Shape {
|
||||
constructor() {
|
||||
Shape.numShapes++;
|
||||
}
|
||||
|
||||
static get numShapes() {
|
||||
return !this.count_ ? 0 : this.count_
|
||||
}
|
||||
|
||||
static set numShapes(val) {
|
||||
this.count_ = val
|
||||
}
|
||||
}
|
||||
|
||||
class Circle extends Shape {
|
||||
constructor(radius) {
|
||||
super();
|
||||
this.radius_ = radius
|
||||
Circle.numCircles++
|
||||
}
|
||||
|
||||
static draw(circle, canvas) {
|
||||
// drawing code
|
||||
}
|
||||
|
||||
static get numCircles() {
|
||||
return !this.count_ ? 0 : this.count_
|
||||
}
|
||||
|
||||
static set numCircles(val) {
|
||||
this.count_ = val
|
||||
}
|
||||
|
||||
area() {
|
||||
return Math.pow(this.radius, 2) * Math.PI
|
||||
}
|
||||
|
||||
get radius() {
|
||||
return this.radius_
|
||||
}
|
||||
|
||||
set radius(radius) {
|
||||
if (!Number.isInteger(radius))
|
||||
throw new TypeError("Circle radius is not an int");
|
||||
this.radius_ = radius
|
||||
}
|
||||
}
|
||||
|
||||
EOF
|
||||
|
||||
parse("class.js", code, "--language=es6", new (Java.extend(visitor_es6, {
|
||||
visitClassDeclaration : function (node, obj) {
|
||||
obj.push(convert(node))
|
||||
}
|
||||
})))
|
||||
|
751
nashorn/test/script/nosecurity/treeapi/class.js.EXPECTED
Normal file
751
nashorn/test/script/nosecurity/treeapi/class.js.EXPECTED
Normal file
@ -0,0 +1,751 @@
|
||||
[
|
||||
{
|
||||
"classElements": [
|
||||
{
|
||||
"getter": {
|
||||
"endPosition": "96",
|
||||
"kind": "FUNCTION_EXPRESSION",
|
||||
"name": "null",
|
||||
"body": {
|
||||
"endPosition": "143",
|
||||
"kind": "BLOCK",
|
||||
"statements": [
|
||||
{
|
||||
"expression": {
|
||||
"condition": {
|
||||
"expression": {
|
||||
"identifier": "count_",
|
||||
"expression": {
|
||||
"endPosition": "118",
|
||||
"kind": "IDENTIFIER",
|
||||
"this": "true",
|
||||
"name": "this",
|
||||
"startPosition": "114"
|
||||
},
|
||||
"endPosition": "125",
|
||||
"kind": "MEMBER_SELECT",
|
||||
"startPosition": "114"
|
||||
},
|
||||
"endPosition": "125",
|
||||
"kind": "LOGICAL_COMPLEMENT",
|
||||
"startPosition": "113"
|
||||
},
|
||||
"endPosition": "143",
|
||||
"kind": "CONDITIONAL_EXPRESSION",
|
||||
"trueExpression": {
|
||||
"endPosition": "129",
|
||||
"kind": "NUMBER_LITERAL",
|
||||
"value": "0",
|
||||
"startPosition": "128"
|
||||
},
|
||||
"falseExpression": {
|
||||
"identifier": "count_",
|
||||
"expression": {
|
||||
"endPosition": "136",
|
||||
"kind": "IDENTIFIER",
|
||||
"this": "true",
|
||||
"name": "this",
|
||||
"startPosition": "132"
|
||||
},
|
||||
"endPosition": "143",
|
||||
"kind": "MEMBER_SELECT",
|
||||
"startPosition": "132"
|
||||
},
|
||||
"startPosition": "126"
|
||||
},
|
||||
"endPosition": "143",
|
||||
"kind": "RETURN",
|
||||
"startPosition": "106"
|
||||
}
|
||||
],
|
||||
"startPosition": "96"
|
||||
},
|
||||
"strict": "true",
|
||||
"startPosition": "96",
|
||||
"parameters": []
|
||||
},
|
||||
"static": "true",
|
||||
"endPosition": "149",
|
||||
"kind": "PROPERTY",
|
||||
"setter": {
|
||||
"endPosition": "181",
|
||||
"kind": "FUNCTION_EXPRESSION",
|
||||
"name": "null",
|
||||
"body": {
|
||||
"endPosition": "209",
|
||||
"kind": "BLOCK",
|
||||
"statements": [
|
||||
{
|
||||
"expression": {
|
||||
"expression": {
|
||||
"endPosition": "209",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "val",
|
||||
"startPosition": "206"
|
||||
},
|
||||
"endPosition": "209",
|
||||
"kind": "ASSIGNMENT",
|
||||
"variable": {
|
||||
"identifier": "count_",
|
||||
"expression": {
|
||||
"endPosition": "196",
|
||||
"kind": "IDENTIFIER",
|
||||
"this": "true",
|
||||
"name": "this",
|
||||
"startPosition": "192"
|
||||
},
|
||||
"endPosition": "203",
|
||||
"kind": "MEMBER_SELECT",
|
||||
"startPosition": "192"
|
||||
},
|
||||
"startPosition": "192"
|
||||
},
|
||||
"endPosition": "209",
|
||||
"kind": "EXPRESSION_STATEMENT",
|
||||
"startPosition": "192"
|
||||
}
|
||||
],
|
||||
"startPosition": "181"
|
||||
},
|
||||
"strict": "true",
|
||||
"startPosition": "181",
|
||||
"parameters": [
|
||||
{
|
||||
"endPosition": "179",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "val",
|
||||
"startPosition": "176"
|
||||
}
|
||||
]
|
||||
},
|
||||
"value": "null",
|
||||
"startPosition": "80",
|
||||
"key": {
|
||||
"endPosition": "93",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "numShapes",
|
||||
"startPosition": "84"
|
||||
}
|
||||
}
|
||||
],
|
||||
"endPosition": "12",
|
||||
"kind": "CLASS",
|
||||
"classHeritage": "null",
|
||||
"name": {
|
||||
"endPosition": "12",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "Shape",
|
||||
"startPosition": "7"
|
||||
},
|
||||
"constructor": {
|
||||
"getter": "null",
|
||||
"endPosition": "67",
|
||||
"kind": "PROPERTY",
|
||||
"setter": "null",
|
||||
"value": {
|
||||
"endPosition": "33",
|
||||
"kind": "FUNCTION_EXPRESSION",
|
||||
"name": {
|
||||
"endPosition": "30",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "constructor",
|
||||
"startPosition": "19"
|
||||
},
|
||||
"body": {
|
||||
"endPosition": "61",
|
||||
"kind": "BLOCK",
|
||||
"statements": [
|
||||
{
|
||||
"expression": {
|
||||
"expression": {
|
||||
"identifier": "numShapes",
|
||||
"expression": {
|
||||
"endPosition": "48",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "Shape",
|
||||
"startPosition": "43"
|
||||
},
|
||||
"endPosition": "58",
|
||||
"kind": "MEMBER_SELECT",
|
||||
"startPosition": "43"
|
||||
},
|
||||
"endPosition": "60",
|
||||
"kind": "POSTFIX_INCREMENT",
|
||||
"startPosition": "43"
|
||||
},
|
||||
"endPosition": "60",
|
||||
"kind": "EXPRESSION_STATEMENT",
|
||||
"startPosition": "43"
|
||||
}
|
||||
],
|
||||
"startPosition": "33"
|
||||
},
|
||||
"strict": "true",
|
||||
"startPosition": "33",
|
||||
"parameters": []
|
||||
},
|
||||
"startPosition": "19",
|
||||
"key": {
|
||||
"endPosition": "30",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "constructor",
|
||||
"startPosition": "19"
|
||||
}
|
||||
},
|
||||
"startPosition": "1"
|
||||
},
|
||||
{
|
||||
"classElements": [
|
||||
{
|
||||
"getter": "null",
|
||||
"static": "true",
|
||||
"endPosition": "419",
|
||||
"kind": "PROPERTY",
|
||||
"setter": "null",
|
||||
"value": {
|
||||
"endPosition": "388",
|
||||
"kind": "FUNCTION_EXPRESSION",
|
||||
"name": {
|
||||
"endPosition": "371",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "draw",
|
||||
"startPosition": "367"
|
||||
},
|
||||
"body": {
|
||||
"endPosition": "389",
|
||||
"kind": "BLOCK",
|
||||
"statements": [],
|
||||
"startPosition": "388"
|
||||
},
|
||||
"strict": "true",
|
||||
"startPosition": "388",
|
||||
"parameters": [
|
||||
{
|
||||
"endPosition": "378",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "circle",
|
||||
"startPosition": "372"
|
||||
},
|
||||
{
|
||||
"endPosition": "386",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "canvas",
|
||||
"startPosition": "380"
|
||||
}
|
||||
]
|
||||
},
|
||||
"startPosition": "367",
|
||||
"key": {
|
||||
"endPosition": "371",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "draw",
|
||||
"startPosition": "367"
|
||||
}
|
||||
},
|
||||
{
|
||||
"getter": {
|
||||
"endPosition": "449",
|
||||
"kind": "FUNCTION_EXPRESSION",
|
||||
"name": "null",
|
||||
"body": {
|
||||
"endPosition": "496",
|
||||
"kind": "BLOCK",
|
||||
"statements": [
|
||||
{
|
||||
"expression": {
|
||||
"condition": {
|
||||
"expression": {
|
||||
"identifier": "count_",
|
||||
"expression": {
|
||||
"endPosition": "471",
|
||||
"kind": "IDENTIFIER",
|
||||
"this": "true",
|
||||
"name": "this",
|
||||
"startPosition": "467"
|
||||
},
|
||||
"endPosition": "478",
|
||||
"kind": "MEMBER_SELECT",
|
||||
"startPosition": "467"
|
||||
},
|
||||
"endPosition": "478",
|
||||
"kind": "LOGICAL_COMPLEMENT",
|
||||
"startPosition": "466"
|
||||
},
|
||||
"endPosition": "496",
|
||||
"kind": "CONDITIONAL_EXPRESSION",
|
||||
"trueExpression": {
|
||||
"endPosition": "482",
|
||||
"kind": "NUMBER_LITERAL",
|
||||
"value": "0",
|
||||
"startPosition": "481"
|
||||
},
|
||||
"falseExpression": {
|
||||
"identifier": "count_",
|
||||
"expression": {
|
||||
"endPosition": "489",
|
||||
"kind": "IDENTIFIER",
|
||||
"this": "true",
|
||||
"name": "this",
|
||||
"startPosition": "485"
|
||||
},
|
||||
"endPosition": "496",
|
||||
"kind": "MEMBER_SELECT",
|
||||
"startPosition": "485"
|
||||
},
|
||||
"startPosition": "479"
|
||||
},
|
||||
"endPosition": "496",
|
||||
"kind": "RETURN",
|
||||
"startPosition": "459"
|
||||
}
|
||||
],
|
||||
"startPosition": "449"
|
||||
},
|
||||
"strict": "true",
|
||||
"startPosition": "449",
|
||||
"parameters": []
|
||||
},
|
||||
"static": "true",
|
||||
"endPosition": "502",
|
||||
"kind": "PROPERTY",
|
||||
"setter": {
|
||||
"endPosition": "535",
|
||||
"kind": "FUNCTION_EXPRESSION",
|
||||
"name": "null",
|
||||
"body": {
|
||||
"endPosition": "563",
|
||||
"kind": "BLOCK",
|
||||
"statements": [
|
||||
{
|
||||
"expression": {
|
||||
"expression": {
|
||||
"endPosition": "563",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "val",
|
||||
"startPosition": "560"
|
||||
},
|
||||
"endPosition": "563",
|
||||
"kind": "ASSIGNMENT",
|
||||
"variable": {
|
||||
"identifier": "count_",
|
||||
"expression": {
|
||||
"endPosition": "550",
|
||||
"kind": "IDENTIFIER",
|
||||
"this": "true",
|
||||
"name": "this",
|
||||
"startPosition": "546"
|
||||
},
|
||||
"endPosition": "557",
|
||||
"kind": "MEMBER_SELECT",
|
||||
"startPosition": "546"
|
||||
},
|
||||
"startPosition": "546"
|
||||
},
|
||||
"endPosition": "563",
|
||||
"kind": "EXPRESSION_STATEMENT",
|
||||
"startPosition": "546"
|
||||
}
|
||||
],
|
||||
"startPosition": "535"
|
||||
},
|
||||
"strict": "true",
|
||||
"startPosition": "535",
|
||||
"parameters": [
|
||||
{
|
||||
"endPosition": "533",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "val",
|
||||
"startPosition": "530"
|
||||
}
|
||||
]
|
||||
},
|
||||
"value": "null",
|
||||
"startPosition": "432",
|
||||
"key": {
|
||||
"endPosition": "446",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "numCircles",
|
||||
"startPosition": "436"
|
||||
}
|
||||
},
|
||||
{
|
||||
"getter": "null",
|
||||
"endPosition": "639",
|
||||
"kind": "PROPERTY",
|
||||
"setter": "null",
|
||||
"value": {
|
||||
"endPosition": "582",
|
||||
"kind": "FUNCTION_EXPRESSION",
|
||||
"name": {
|
||||
"endPosition": "579",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "area",
|
||||
"startPosition": "575"
|
||||
},
|
||||
"body": {
|
||||
"endPosition": "633",
|
||||
"kind": "BLOCK",
|
||||
"statements": [
|
||||
{
|
||||
"expression": {
|
||||
"leftOperand": {
|
||||
"endPosition": "623",
|
||||
"kind": "FUNCTION_INVOCATION",
|
||||
"functionSelect": {
|
||||
"identifier": "pow",
|
||||
"expression": {
|
||||
"endPosition": "603",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "Math",
|
||||
"startPosition": "599"
|
||||
},
|
||||
"endPosition": "607",
|
||||
"kind": "MEMBER_SELECT",
|
||||
"startPosition": "599"
|
||||
},
|
||||
"arguments": [
|
||||
{
|
||||
"identifier": "radius",
|
||||
"expression": {
|
||||
"endPosition": "612",
|
||||
"kind": "IDENTIFIER",
|
||||
"this": "true",
|
||||
"name": "this",
|
||||
"startPosition": "608"
|
||||
},
|
||||
"endPosition": "619",
|
||||
"kind": "MEMBER_SELECT",
|
||||
"startPosition": "608"
|
||||
},
|
||||
{
|
||||
"endPosition": "622",
|
||||
"kind": "NUMBER_LITERAL",
|
||||
"value": "2",
|
||||
"startPosition": "621"
|
||||
}
|
||||
],
|
||||
"startPosition": "599"
|
||||
},
|
||||
"endPosition": "633",
|
||||
"kind": "MULTIPLY",
|
||||
"rightOperand": {
|
||||
"identifier": "PI",
|
||||
"expression": {
|
||||
"endPosition": "630",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "Math",
|
||||
"startPosition": "626"
|
||||
},
|
||||
"endPosition": "633",
|
||||
"kind": "MEMBER_SELECT",
|
||||
"startPosition": "626"
|
||||
},
|
||||
"startPosition": "599"
|
||||
},
|
||||
"endPosition": "633",
|
||||
"kind": "RETURN",
|
||||
"startPosition": "592"
|
||||
}
|
||||
],
|
||||
"startPosition": "582"
|
||||
},
|
||||
"strict": "true",
|
||||
"startPosition": "582",
|
||||
"parameters": []
|
||||
},
|
||||
"startPosition": "575",
|
||||
"key": {
|
||||
"endPosition": "579",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "area",
|
||||
"startPosition": "575"
|
||||
}
|
||||
},
|
||||
{
|
||||
"getter": {
|
||||
"endPosition": "658",
|
||||
"kind": "FUNCTION_EXPRESSION",
|
||||
"name": "null",
|
||||
"body": {
|
||||
"endPosition": "687",
|
||||
"kind": "BLOCK",
|
||||
"statements": [
|
||||
{
|
||||
"expression": {
|
||||
"identifier": "radius_",
|
||||
"expression": {
|
||||
"endPosition": "679",
|
||||
"kind": "IDENTIFIER",
|
||||
"this": "true",
|
||||
"name": "this",
|
||||
"startPosition": "675"
|
||||
},
|
||||
"endPosition": "687",
|
||||
"kind": "MEMBER_SELECT",
|
||||
"startPosition": "675"
|
||||
},
|
||||
"endPosition": "687",
|
||||
"kind": "RETURN",
|
||||
"startPosition": "668"
|
||||
}
|
||||
],
|
||||
"startPosition": "658"
|
||||
},
|
||||
"strict": "true",
|
||||
"startPosition": "658",
|
||||
"parameters": []
|
||||
},
|
||||
"endPosition": "693",
|
||||
"kind": "PROPERTY",
|
||||
"setter": {
|
||||
"endPosition": "718",
|
||||
"kind": "FUNCTION_EXPRESSION",
|
||||
"name": "null",
|
||||
"body": {
|
||||
"endPosition": "852",
|
||||
"kind": "BLOCK",
|
||||
"statements": [
|
||||
{
|
||||
"condition": {
|
||||
"expression": {
|
||||
"endPosition": "757",
|
||||
"kind": "FUNCTION_INVOCATION",
|
||||
"functionSelect": {
|
||||
"identifier": "isInteger",
|
||||
"expression": {
|
||||
"endPosition": "739",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "Number",
|
||||
"startPosition": "733"
|
||||
},
|
||||
"endPosition": "749",
|
||||
"kind": "MEMBER_SELECT",
|
||||
"startPosition": "733"
|
||||
},
|
||||
"arguments": [
|
||||
{
|
||||
"endPosition": "756",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "radius",
|
||||
"startPosition": "750"
|
||||
}
|
||||
],
|
||||
"startPosition": "733"
|
||||
},
|
||||
"endPosition": "757",
|
||||
"kind": "LOGICAL_COMPLEMENT",
|
||||
"startPosition": "732"
|
||||
},
|
||||
"elseStatement": "null",
|
||||
"endPosition": "822",
|
||||
"kind": "IF",
|
||||
"startPosition": "728",
|
||||
"thenStatement": {
|
||||
"expression": {
|
||||
"constructorExpression": {
|
||||
"endPosition": "821",
|
||||
"kind": "FUNCTION_INVOCATION",
|
||||
"functionSelect": {
|
||||
"endPosition": "790",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "TypeError",
|
||||
"startPosition": "781"
|
||||
},
|
||||
"arguments": [
|
||||
{
|
||||
"endPosition": "819",
|
||||
"kind": "STRING_LITERAL",
|
||||
"value": "Circle radius is not an int",
|
||||
"startPosition": "792"
|
||||
}
|
||||
],
|
||||
"startPosition": "781"
|
||||
},
|
||||
"endPosition": "821",
|
||||
"kind": "NEW",
|
||||
"startPosition": "777"
|
||||
},
|
||||
"endPosition": "822",
|
||||
"kind": "THROW",
|
||||
"startPosition": "771"
|
||||
}
|
||||
},
|
||||
{
|
||||
"expression": {
|
||||
"expression": {
|
||||
"endPosition": "852",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "radius",
|
||||
"startPosition": "846"
|
||||
},
|
||||
"endPosition": "852",
|
||||
"kind": "ASSIGNMENT",
|
||||
"variable": {
|
||||
"identifier": "radius_",
|
||||
"expression": {
|
||||
"endPosition": "835",
|
||||
"kind": "IDENTIFIER",
|
||||
"this": "true",
|
||||
"name": "this",
|
||||
"startPosition": "831"
|
||||
},
|
||||
"endPosition": "843",
|
||||
"kind": "MEMBER_SELECT",
|
||||
"startPosition": "831"
|
||||
},
|
||||
"startPosition": "831"
|
||||
},
|
||||
"endPosition": "852",
|
||||
"kind": "EXPRESSION_STATEMENT",
|
||||
"startPosition": "831"
|
||||
}
|
||||
],
|
||||
"startPosition": "718"
|
||||
},
|
||||
"strict": "true",
|
||||
"startPosition": "718",
|
||||
"parameters": [
|
||||
{
|
||||
"endPosition": "716",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "radius",
|
||||
"startPosition": "710"
|
||||
}
|
||||
]
|
||||
},
|
||||
"value": "null",
|
||||
"startPosition": "645",
|
||||
"key": {
|
||||
"endPosition": "655",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "radius",
|
||||
"startPosition": "649"
|
||||
}
|
||||
}
|
||||
],
|
||||
"endPosition": "231",
|
||||
"kind": "CLASS",
|
||||
"classHeritage": {
|
||||
"endPosition": "245",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "Shape",
|
||||
"startPosition": "240"
|
||||
},
|
||||
"name": {
|
||||
"endPosition": "231",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "Circle",
|
||||
"startPosition": "225"
|
||||
},
|
||||
"constructor": {
|
||||
"getter": "null",
|
||||
"endPosition": "354",
|
||||
"kind": "PROPERTY",
|
||||
"setter": "null",
|
||||
"value": {
|
||||
"endPosition": "272",
|
||||
"kind": "FUNCTION_EXPRESSION",
|
||||
"name": {
|
||||
"endPosition": "263",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "constructor",
|
||||
"startPosition": "252"
|
||||
},
|
||||
"body": {
|
||||
"endPosition": "348",
|
||||
"kind": "BLOCK",
|
||||
"statements": [
|
||||
{
|
||||
"expression": {
|
||||
"endPosition": "289",
|
||||
"kind": "FUNCTION_INVOCATION",
|
||||
"functionSelect": {
|
||||
"super": "true",
|
||||
"endPosition": "287",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "super",
|
||||
"startPosition": "282"
|
||||
},
|
||||
"arguments": [],
|
||||
"startPosition": "282"
|
||||
},
|
||||
"endPosition": "289",
|
||||
"kind": "EXPRESSION_STATEMENT",
|
||||
"startPosition": "282"
|
||||
},
|
||||
{
|
||||
"expression": {
|
||||
"expression": {
|
||||
"endPosition": "320",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "radius",
|
||||
"startPosition": "314"
|
||||
},
|
||||
"endPosition": "320",
|
||||
"kind": "ASSIGNMENT",
|
||||
"variable": {
|
||||
"identifier": "radius_",
|
||||
"expression": {
|
||||
"endPosition": "303",
|
||||
"kind": "IDENTIFIER",
|
||||
"this": "true",
|
||||
"name": "this",
|
||||
"startPosition": "299"
|
||||
},
|
||||
"endPosition": "311",
|
||||
"kind": "MEMBER_SELECT",
|
||||
"startPosition": "299"
|
||||
},
|
||||
"startPosition": "299"
|
||||
},
|
||||
"endPosition": "320",
|
||||
"kind": "EXPRESSION_STATEMENT",
|
||||
"startPosition": "299"
|
||||
},
|
||||
{
|
||||
"expression": {
|
||||
"expression": {
|
||||
"identifier": "numCircles",
|
||||
"expression": {
|
||||
"endPosition": "335",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "Circle",
|
||||
"startPosition": "329"
|
||||
},
|
||||
"endPosition": "346",
|
||||
"kind": "MEMBER_SELECT",
|
||||
"startPosition": "329"
|
||||
},
|
||||
"endPosition": "348",
|
||||
"kind": "POSTFIX_INCREMENT",
|
||||
"startPosition": "329"
|
||||
},
|
||||
"endPosition": "348",
|
||||
"kind": "EXPRESSION_STATEMENT",
|
||||
"startPosition": "329"
|
||||
}
|
||||
],
|
||||
"startPosition": "272"
|
||||
},
|
||||
"strict": "true",
|
||||
"startPosition": "272",
|
||||
"parameters": [
|
||||
{
|
||||
"endPosition": "270",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "radius",
|
||||
"startPosition": "264"
|
||||
}
|
||||
]
|
||||
},
|
||||
"startPosition": "252",
|
||||
"key": {
|
||||
"endPosition": "263",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "constructor",
|
||||
"startPosition": "252"
|
||||
}
|
||||
},
|
||||
"startPosition": "219"
|
||||
}
|
||||
]
|
45
nashorn/test/script/nosecurity/treeapi/const.js
Normal file
45
nashorn/test/script/nosecurity/treeapi/const.js
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests to check representation of ES6 consts.
|
||||
*
|
||||
* @test
|
||||
* @option -scripting
|
||||
* @run
|
||||
*/
|
||||
|
||||
load(__DIR__ + "utils.js")
|
||||
|
||||
var code = <<EOF
|
||||
|
||||
const PI = 3.14;
|
||||
|
||||
EOF
|
||||
|
||||
parse("generator.js", code, "--language=es6", new (Java.extend(visitor_es6, {
|
||||
visitVariable : function (node, obj) {
|
||||
obj.push(convert(node))
|
||||
}
|
||||
})))
|
||||
|
20
nashorn/test/script/nosecurity/treeapi/const.js.EXPECTED
Normal file
20
nashorn/test/script/nosecurity/treeapi/const.js.EXPECTED
Normal file
@ -0,0 +1,20 @@
|
||||
[
|
||||
{
|
||||
"const": "true",
|
||||
"endPosition": "16",
|
||||
"kind": "VARIABLE",
|
||||
"binding": {
|
||||
"endPosition": "9",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "PI",
|
||||
"startPosition": "7"
|
||||
},
|
||||
"startPosition": "1",
|
||||
"initializer": {
|
||||
"endPosition": "16",
|
||||
"kind": "NUMBER_LITERAL",
|
||||
"value": "3.14",
|
||||
"startPosition": "12"
|
||||
}
|
||||
}
|
||||
]
|
52
nashorn/test/script/nosecurity/treeapi/defaultparams.js
Normal file
52
nashorn/test/script/nosecurity/treeapi/defaultparams.js
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests to check representation of ES6 default parameters.
|
||||
*
|
||||
* @test
|
||||
* @option -scripting
|
||||
* @run
|
||||
*/
|
||||
|
||||
load(__DIR__ + "utils.js")
|
||||
|
||||
var code = <<EOF
|
||||
|
||||
function func(x = 3, y) {
|
||||
return x + y;
|
||||
}
|
||||
|
||||
var f = function (x = 4, y = 5) { return x * y }
|
||||
|
||||
EOF
|
||||
|
||||
parse("defaultparams.js", code, "--language=es6", new (Java.extend(visitor_es6, {
|
||||
visitFunctionDeclaration : function (node, obj) {
|
||||
obj.push(convert(node))
|
||||
},
|
||||
visitVariable : function (node, obj) {
|
||||
obj.push(convert(node))
|
||||
}
|
||||
})))
|
||||
|
151
nashorn/test/script/nosecurity/treeapi/defaultparams.js.EXPECTED
Normal file
151
nashorn/test/script/nosecurity/treeapi/defaultparams.js.EXPECTED
Normal file
@ -0,0 +1,151 @@
|
||||
[
|
||||
{
|
||||
"endPosition": "46",
|
||||
"kind": "FUNCTION",
|
||||
"name": {
|
||||
"endPosition": "14",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "func",
|
||||
"startPosition": "10"
|
||||
},
|
||||
"body": {
|
||||
"endPosition": "44",
|
||||
"kind": "BLOCK",
|
||||
"statements": [
|
||||
{
|
||||
"expression": {
|
||||
"leftOperand": {
|
||||
"endPosition": "39",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "x",
|
||||
"startPosition": "38"
|
||||
},
|
||||
"endPosition": "43",
|
||||
"kind": "PLUS",
|
||||
"rightOperand": {
|
||||
"endPosition": "43",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "y",
|
||||
"startPosition": "42"
|
||||
},
|
||||
"startPosition": "38"
|
||||
},
|
||||
"endPosition": "44",
|
||||
"kind": "RETURN",
|
||||
"startPosition": "31"
|
||||
}
|
||||
],
|
||||
"startPosition": "25"
|
||||
},
|
||||
"strict": "false",
|
||||
"startPosition": "1",
|
||||
"parameters": [
|
||||
{
|
||||
"expression": {
|
||||
"endPosition": "20",
|
||||
"kind": "NUMBER_LITERAL",
|
||||
"value": "3",
|
||||
"startPosition": "19"
|
||||
},
|
||||
"endPosition": "20",
|
||||
"kind": "ASSIGNMENT",
|
||||
"variable": {
|
||||
"endPosition": "16",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "x",
|
||||
"startPosition": "15"
|
||||
},
|
||||
"startPosition": "15"
|
||||
},
|
||||
{
|
||||
"endPosition": "23",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "y",
|
||||
"startPosition": "22"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"endPosition": "96",
|
||||
"kind": "VARIABLE",
|
||||
"binding": {
|
||||
"endPosition": "53",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "f",
|
||||
"startPosition": "52"
|
||||
},
|
||||
"startPosition": "48",
|
||||
"initializer": {
|
||||
"endPosition": "80",
|
||||
"kind": "FUNCTION_EXPRESSION",
|
||||
"name": "null",
|
||||
"body": {
|
||||
"endPosition": "94",
|
||||
"kind": "BLOCK",
|
||||
"statements": [
|
||||
{
|
||||
"expression": {
|
||||
"leftOperand": {
|
||||
"endPosition": "90",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "x",
|
||||
"startPosition": "89"
|
||||
},
|
||||
"endPosition": "94",
|
||||
"kind": "MULTIPLY",
|
||||
"rightOperand": {
|
||||
"endPosition": "94",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "y",
|
||||
"startPosition": "93"
|
||||
},
|
||||
"startPosition": "89"
|
||||
},
|
||||
"endPosition": "94",
|
||||
"kind": "RETURN",
|
||||
"startPosition": "82"
|
||||
}
|
||||
],
|
||||
"startPosition": "80"
|
||||
},
|
||||
"strict": "false",
|
||||
"startPosition": "80",
|
||||
"parameters": [
|
||||
{
|
||||
"expression": {
|
||||
"endPosition": "71",
|
||||
"kind": "NUMBER_LITERAL",
|
||||
"value": "4",
|
||||
"startPosition": "70"
|
||||
},
|
||||
"endPosition": "71",
|
||||
"kind": "ASSIGNMENT",
|
||||
"variable": {
|
||||
"endPosition": "67",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "x",
|
||||
"startPosition": "66"
|
||||
},
|
||||
"startPosition": "66"
|
||||
},
|
||||
{
|
||||
"expression": {
|
||||
"endPosition": "78",
|
||||
"kind": "NUMBER_LITERAL",
|
||||
"value": "5",
|
||||
"startPosition": "77"
|
||||
},
|
||||
"endPosition": "78",
|
||||
"kind": "ASSIGNMENT",
|
||||
"variable": {
|
||||
"endPosition": "74",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "y",
|
||||
"startPosition": "73"
|
||||
},
|
||||
"startPosition": "73"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests to check representation of ES6 destructuring assignments.
|
||||
*
|
||||
* @test
|
||||
* @option -scripting
|
||||
* @run
|
||||
*/
|
||||
|
||||
load(__DIR__ + "utils.js")
|
||||
|
||||
var code = <<EOF
|
||||
|
||||
var a, b;
|
||||
[a, b] = [1, 2];
|
||||
({a, b} = {a:11, b:12});
|
||||
|
||||
EOF
|
||||
|
||||
parse("destructuring_assign.js", code, "--language=es6", new (Java.extend(visitor_es6, {
|
||||
visitAssignment : function (node, obj) {
|
||||
obj.push(convert(node))
|
||||
},
|
||||
visitVariable : function (node, obj) {
|
||||
obj.push(convert(node))
|
||||
}
|
||||
})))
|
||||
|
@ -0,0 +1,164 @@
|
||||
[
|
||||
{
|
||||
"endPosition": "6",
|
||||
"kind": "VARIABLE",
|
||||
"binding": {
|
||||
"endPosition": "6",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "a",
|
||||
"startPosition": "5"
|
||||
},
|
||||
"startPosition": "1",
|
||||
"initializer": "null"
|
||||
},
|
||||
{
|
||||
"endPosition": "9",
|
||||
"kind": "VARIABLE",
|
||||
"binding": {
|
||||
"endPosition": "9",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "b",
|
||||
"startPosition": "8"
|
||||
},
|
||||
"startPosition": "1",
|
||||
"initializer": "null"
|
||||
},
|
||||
{
|
||||
"expression": {
|
||||
"endPosition": "26",
|
||||
"kind": "ARRAY_LITERAL",
|
||||
"elements": [
|
||||
{
|
||||
"endPosition": "22",
|
||||
"kind": "NUMBER_LITERAL",
|
||||
"value": "1",
|
||||
"startPosition": "21"
|
||||
},
|
||||
{
|
||||
"endPosition": "25",
|
||||
"kind": "NUMBER_LITERAL",
|
||||
"value": "2",
|
||||
"startPosition": "24"
|
||||
}
|
||||
],
|
||||
"startPosition": "20"
|
||||
},
|
||||
"endPosition": "26",
|
||||
"kind": "ASSIGNMENT",
|
||||
"variable": {
|
||||
"endPosition": "17",
|
||||
"kind": "ARRAY_LITERAL",
|
||||
"elements": [
|
||||
{
|
||||
"endPosition": "13",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "a",
|
||||
"startPosition": "12"
|
||||
},
|
||||
{
|
||||
"endPosition": "16",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "b",
|
||||
"startPosition": "15"
|
||||
}
|
||||
],
|
||||
"startPosition": "11"
|
||||
},
|
||||
"startPosition": "11"
|
||||
},
|
||||
{
|
||||
"expression": {
|
||||
"endPosition": "50",
|
||||
"kind": "OBJECT_LITERAL",
|
||||
"startPosition": "38",
|
||||
"properties": [
|
||||
{
|
||||
"getter": "null",
|
||||
"endPosition": "43",
|
||||
"kind": "PROPERTY",
|
||||
"setter": "null",
|
||||
"value": {
|
||||
"endPosition": "43",
|
||||
"kind": "NUMBER_LITERAL",
|
||||
"value": "11",
|
||||
"startPosition": "41"
|
||||
},
|
||||
"startPosition": "39",
|
||||
"key": {
|
||||
"endPosition": "40",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "a",
|
||||
"startPosition": "39"
|
||||
}
|
||||
},
|
||||
{
|
||||
"getter": "null",
|
||||
"endPosition": "49",
|
||||
"kind": "PROPERTY",
|
||||
"setter": "null",
|
||||
"value": {
|
||||
"endPosition": "49",
|
||||
"kind": "NUMBER_LITERAL",
|
||||
"value": "12",
|
||||
"startPosition": "47"
|
||||
},
|
||||
"startPosition": "45",
|
||||
"key": {
|
||||
"endPosition": "46",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "b",
|
||||
"startPosition": "45"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"endPosition": "50",
|
||||
"kind": "ASSIGNMENT",
|
||||
"variable": {
|
||||
"endPosition": "35",
|
||||
"kind": "OBJECT_LITERAL",
|
||||
"startPosition": "29",
|
||||
"properties": [
|
||||
{
|
||||
"getter": "null",
|
||||
"endPosition": "31",
|
||||
"kind": "PROPERTY",
|
||||
"setter": "null",
|
||||
"value": {
|
||||
"endPosition": "31",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "a",
|
||||
"startPosition": "30"
|
||||
},
|
||||
"startPosition": "30",
|
||||
"key": {
|
||||
"endPosition": "31",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "a",
|
||||
"startPosition": "30"
|
||||
}
|
||||
},
|
||||
{
|
||||
"getter": "null",
|
||||
"endPosition": "34",
|
||||
"kind": "PROPERTY",
|
||||
"setter": "null",
|
||||
"value": {
|
||||
"endPosition": "34",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "b",
|
||||
"startPosition": "33"
|
||||
},
|
||||
"startPosition": "33",
|
||||
"key": {
|
||||
"endPosition": "34",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "b",
|
||||
"startPosition": "33"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"startPosition": "29"
|
||||
}
|
||||
]
|
49
nashorn/test/script/nosecurity/treeapi/destructuring_decl.js
Normal file
49
nashorn/test/script/nosecurity/treeapi/destructuring_decl.js
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests to check representation of ES6 destructuring initializatons, assignemts.
|
||||
*
|
||||
* @test
|
||||
* @option -scripting
|
||||
* @run
|
||||
*/
|
||||
|
||||
load(__DIR__ + "utils.js")
|
||||
|
||||
var code = <<EOF
|
||||
|
||||
var [a, b] = [1, 2];
|
||||
|
||||
var { x, y } = obj;
|
||||
EOF
|
||||
|
||||
parse("destructuring_assign.js", code, "--language=es6", new (Java.extend(visitor_es6, {
|
||||
visitAssignment : function (node, obj) {
|
||||
obj.push(convert(node))
|
||||
},
|
||||
visitVariable : function (node, obj) {
|
||||
obj.push(convert(node))
|
||||
}
|
||||
})))
|
||||
|
@ -0,0 +1,101 @@
|
||||
[
|
||||
{
|
||||
"endPosition": "20",
|
||||
"kind": "VARIABLE",
|
||||
"binding": {
|
||||
"endPosition": "11",
|
||||
"kind": "ARRAY_LITERAL",
|
||||
"elements": [
|
||||
{
|
||||
"endPosition": "7",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "a",
|
||||
"startPosition": "6"
|
||||
},
|
||||
{
|
||||
"endPosition": "10",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "b",
|
||||
"startPosition": "9"
|
||||
}
|
||||
],
|
||||
"startPosition": "5"
|
||||
},
|
||||
"startPosition": "1",
|
||||
"initializer": {
|
||||
"endPosition": "20",
|
||||
"kind": "ARRAY_LITERAL",
|
||||
"elements": [
|
||||
{
|
||||
"endPosition": "16",
|
||||
"kind": "NUMBER_LITERAL",
|
||||
"value": "1",
|
||||
"startPosition": "15"
|
||||
},
|
||||
{
|
||||
"endPosition": "19",
|
||||
"kind": "NUMBER_LITERAL",
|
||||
"value": "2",
|
||||
"startPosition": "18"
|
||||
}
|
||||
],
|
||||
"startPosition": "14"
|
||||
}
|
||||
},
|
||||
{
|
||||
"endPosition": "41",
|
||||
"kind": "VARIABLE",
|
||||
"binding": {
|
||||
"endPosition": "35",
|
||||
"kind": "OBJECT_LITERAL",
|
||||
"startPosition": "27",
|
||||
"properties": [
|
||||
{
|
||||
"getter": "null",
|
||||
"endPosition": "30",
|
||||
"kind": "PROPERTY",
|
||||
"setter": "null",
|
||||
"value": {
|
||||
"endPosition": "30",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "x",
|
||||
"startPosition": "29"
|
||||
},
|
||||
"startPosition": "29",
|
||||
"key": {
|
||||
"endPosition": "30",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "x",
|
||||
"startPosition": "29"
|
||||
}
|
||||
},
|
||||
{
|
||||
"getter": "null",
|
||||
"endPosition": "33",
|
||||
"kind": "PROPERTY",
|
||||
"setter": "null",
|
||||
"value": {
|
||||
"endPosition": "33",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "y",
|
||||
"startPosition": "32"
|
||||
},
|
||||
"startPosition": "32",
|
||||
"key": {
|
||||
"endPosition": "33",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "y",
|
||||
"startPosition": "32"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"startPosition": "23",
|
||||
"initializer": {
|
||||
"endPosition": "41",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "obj",
|
||||
"startPosition": "38"
|
||||
}
|
||||
}
|
||||
]
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests to check representation of ES6 default parameters.
|
||||
*
|
||||
* @test
|
||||
* @option -scripting
|
||||
* @run
|
||||
*/
|
||||
|
||||
load(__DIR__ + "utils.js")
|
||||
|
||||
var code = <<EOF
|
||||
|
||||
function func({x, y}) {
|
||||
}
|
||||
|
||||
var f = function({a, b}) { }
|
||||
|
||||
function x({x, y} = { x: 44, y: 45 }) {}
|
||||
|
||||
EOF
|
||||
|
||||
parse("destructuring_params.js", code, "--language=es6", new (Java.extend(visitor_es6, {
|
||||
visitFunctionDeclaration : function (node, obj) {
|
||||
obj.push(convert(node))
|
||||
},
|
||||
visitVariable : function (node, obj) {
|
||||
obj.push(convert(node))
|
||||
}
|
||||
})))
|
||||
|
@ -0,0 +1,253 @@
|
||||
[
|
||||
{
|
||||
"endPosition": "26",
|
||||
"kind": "FUNCTION",
|
||||
"name": {
|
||||
"endPosition": "14",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "func",
|
||||
"startPosition": "10"
|
||||
},
|
||||
"body": {
|
||||
"endPosition": "24",
|
||||
"kind": "BLOCK",
|
||||
"statements": [],
|
||||
"startPosition": "23"
|
||||
},
|
||||
"strict": "false",
|
||||
"startPosition": "1",
|
||||
"parameters": [
|
||||
{
|
||||
"endPosition": "21",
|
||||
"kind": "OBJECT_LITERAL",
|
||||
"startPosition": "15",
|
||||
"properties": [
|
||||
{
|
||||
"getter": "null",
|
||||
"endPosition": "17",
|
||||
"kind": "PROPERTY",
|
||||
"setter": "null",
|
||||
"value": {
|
||||
"endPosition": "17",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "x",
|
||||
"startPosition": "16"
|
||||
},
|
||||
"startPosition": "16",
|
||||
"key": {
|
||||
"endPosition": "17",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "x",
|
||||
"startPosition": "16"
|
||||
}
|
||||
},
|
||||
{
|
||||
"getter": "null",
|
||||
"endPosition": "20",
|
||||
"kind": "PROPERTY",
|
||||
"setter": "null",
|
||||
"value": {
|
||||
"endPosition": "20",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "y",
|
||||
"startPosition": "19"
|
||||
},
|
||||
"startPosition": "19",
|
||||
"key": {
|
||||
"endPosition": "20",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "y",
|
||||
"startPosition": "19"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"endPosition": "56",
|
||||
"kind": "VARIABLE",
|
||||
"binding": {
|
||||
"endPosition": "33",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "f",
|
||||
"startPosition": "32"
|
||||
},
|
||||
"startPosition": "28",
|
||||
"initializer": {
|
||||
"endPosition": "53",
|
||||
"kind": "FUNCTION_EXPRESSION",
|
||||
"name": "null",
|
||||
"body": {
|
||||
"endPosition": "54",
|
||||
"kind": "BLOCK",
|
||||
"statements": [],
|
||||
"startPosition": "53"
|
||||
},
|
||||
"strict": "false",
|
||||
"startPosition": "53",
|
||||
"parameters": [
|
||||
{
|
||||
"endPosition": "51",
|
||||
"kind": "OBJECT_LITERAL",
|
||||
"startPosition": "45",
|
||||
"properties": [
|
||||
{
|
||||
"getter": "null",
|
||||
"endPosition": "47",
|
||||
"kind": "PROPERTY",
|
||||
"setter": "null",
|
||||
"value": {
|
||||
"endPosition": "47",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "a",
|
||||
"startPosition": "46"
|
||||
},
|
||||
"startPosition": "46",
|
||||
"key": {
|
||||
"endPosition": "47",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "a",
|
||||
"startPosition": "46"
|
||||
}
|
||||
},
|
||||
{
|
||||
"getter": "null",
|
||||
"endPosition": "50",
|
||||
"kind": "PROPERTY",
|
||||
"setter": "null",
|
||||
"value": {
|
||||
"endPosition": "50",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "b",
|
||||
"startPosition": "49"
|
||||
},
|
||||
"startPosition": "49",
|
||||
"key": {
|
||||
"endPosition": "50",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "b",
|
||||
"startPosition": "49"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"endPosition": "98",
|
||||
"kind": "FUNCTION",
|
||||
"name": {
|
||||
"endPosition": "68",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "x",
|
||||
"startPosition": "67"
|
||||
},
|
||||
"body": {
|
||||
"endPosition": "97",
|
||||
"kind": "BLOCK",
|
||||
"statements": [],
|
||||
"startPosition": "96"
|
||||
},
|
||||
"strict": "false",
|
||||
"startPosition": "58",
|
||||
"parameters": [
|
||||
{
|
||||
"expression": {
|
||||
"endPosition": "94",
|
||||
"kind": "OBJECT_LITERAL",
|
||||
"startPosition": "78",
|
||||
"properties": [
|
||||
{
|
||||
"getter": "null",
|
||||
"endPosition": "85",
|
||||
"kind": "PROPERTY",
|
||||
"setter": "null",
|
||||
"value": {
|
||||
"endPosition": "85",
|
||||
"kind": "NUMBER_LITERAL",
|
||||
"value": "44",
|
||||
"startPosition": "83"
|
||||
},
|
||||
"startPosition": "80",
|
||||
"key": {
|
||||
"endPosition": "81",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "x",
|
||||
"startPosition": "80"
|
||||
}
|
||||
},
|
||||
{
|
||||
"getter": "null",
|
||||
"endPosition": "92",
|
||||
"kind": "PROPERTY",
|
||||
"setter": "null",
|
||||
"value": {
|
||||
"endPosition": "92",
|
||||
"kind": "NUMBER_LITERAL",
|
||||
"value": "45",
|
||||
"startPosition": "90"
|
||||
},
|
||||
"startPosition": "87",
|
||||
"key": {
|
||||
"endPosition": "88",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "y",
|
||||
"startPosition": "87"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"endPosition": "94",
|
||||
"kind": "ASSIGNMENT",
|
||||
"variable": {
|
||||
"endPosition": "75",
|
||||
"kind": "OBJECT_LITERAL",
|
||||
"startPosition": "69",
|
||||
"properties": [
|
||||
{
|
||||
"getter": "null",
|
||||
"endPosition": "71",
|
||||
"kind": "PROPERTY",
|
||||
"setter": "null",
|
||||
"value": {
|
||||
"endPosition": "71",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "x",
|
||||
"startPosition": "70"
|
||||
},
|
||||
"startPosition": "70",
|
||||
"key": {
|
||||
"endPosition": "71",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "x",
|
||||
"startPosition": "70"
|
||||
}
|
||||
},
|
||||
{
|
||||
"getter": "null",
|
||||
"endPosition": "74",
|
||||
"kind": "PROPERTY",
|
||||
"setter": "null",
|
||||
"value": {
|
||||
"endPosition": "74",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "y",
|
||||
"startPosition": "73"
|
||||
},
|
||||
"startPosition": "73",
|
||||
"key": {
|
||||
"endPosition": "74",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "y",
|
||||
"startPosition": "73"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"startPosition": "69"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
@ -252,4 +252,4 @@
|
||||
],
|
||||
"startPosition": "139"
|
||||
}
|
||||
]
|
||||
]
|
||||
|
@ -2,7 +2,12 @@
|
||||
{
|
||||
"endPosition": "17",
|
||||
"kind": "FUNCTION",
|
||||
"name": "a",
|
||||
"name": {
|
||||
"endPosition": "11",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "a",
|
||||
"startPosition": "10"
|
||||
},
|
||||
"body": {
|
||||
"endPosition": "16",
|
||||
"kind": "BLOCK",
|
||||
@ -16,7 +21,12 @@
|
||||
{
|
||||
"endPosition": "62",
|
||||
"kind": "FUNCTION",
|
||||
"name": "d",
|
||||
"name": {
|
||||
"endPosition": "28",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "d",
|
||||
"startPosition": "27"
|
||||
},
|
||||
"body": {
|
||||
"endPosition": "60",
|
||||
"kind": "BLOCK",
|
||||
@ -24,7 +34,12 @@
|
||||
{
|
||||
"endPosition": "60",
|
||||
"kind": "FUNCTION",
|
||||
"name": "e",
|
||||
"name": {
|
||||
"endPosition": "46",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "e",
|
||||
"startPosition": "45"
|
||||
},
|
||||
"body": {
|
||||
"endPosition": "59",
|
||||
"kind": "BLOCK",
|
||||
@ -70,7 +85,12 @@
|
||||
{
|
||||
"endPosition": "89",
|
||||
"kind": "FUNCTION",
|
||||
"name": "f",
|
||||
"name": {
|
||||
"endPosition": "73",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "f",
|
||||
"startPosition": "72"
|
||||
},
|
||||
"body": {
|
||||
"endPosition": "88",
|
||||
"kind": "BLOCK",
|
||||
@ -122,7 +142,12 @@
|
||||
{
|
||||
"endPosition": "121",
|
||||
"kind": "FUNCTION",
|
||||
"name": "j",
|
||||
"name": {
|
||||
"endPosition": "100",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "j",
|
||||
"startPosition": "99"
|
||||
},
|
||||
"body": {
|
||||
"endPosition": "120",
|
||||
"kind": "BLOCK",
|
||||
@ -158,4 +183,4 @@
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
]
|
||||
|
@ -125,4 +125,4 @@
|
||||
"startPosition": "110",
|
||||
"parameters": []
|
||||
}
|
||||
]
|
||||
]
|
||||
|
67
nashorn/test/script/nosecurity/treeapi/generator.js
Normal file
67
nashorn/test/script/nosecurity/treeapi/generator.js
Normal file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests to check representation of ES6 generators.
|
||||
*
|
||||
* @test
|
||||
* @option -scripting
|
||||
* @run
|
||||
*/
|
||||
|
||||
load(__DIR__ + "utils.js")
|
||||
|
||||
var code = <<EOF
|
||||
|
||||
function* id(){
|
||||
var idx = 0;
|
||||
while(idx < 3)
|
||||
yield idx++;
|
||||
}
|
||||
|
||||
var obj = {
|
||||
*q (x, y) {
|
||||
yield 1;
|
||||
}
|
||||
};
|
||||
|
||||
var f = {
|
||||
[Symbol.iterator]: function*() {
|
||||
var cur = 1;
|
||||
for (;;) {
|
||||
yield cur;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
EOF
|
||||
|
||||
parse("generator.js", code, "--language=es6", new (Java.extend(visitor_es6, {
|
||||
visitFunctionDeclaration : function (node, obj) {
|
||||
obj.push(convert(node))
|
||||
},
|
||||
visitVariable : function (node, obj) {
|
||||
obj.push(convert(node))
|
||||
}
|
||||
})))
|
||||
|
266
nashorn/test/script/nosecurity/treeapi/generator.js.EXPECTED
Normal file
266
nashorn/test/script/nosecurity/treeapi/generator.js.EXPECTED
Normal file
@ -0,0 +1,266 @@
|
||||
[
|
||||
{
|
||||
"endPosition": "67",
|
||||
"kind": "FUNCTION",
|
||||
"name": {
|
||||
"endPosition": "13",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "id",
|
||||
"startPosition": "11"
|
||||
},
|
||||
"generator": "true",
|
||||
"body": {
|
||||
"endPosition": "65",
|
||||
"kind": "BLOCK",
|
||||
"statements": [
|
||||
{
|
||||
"endPosition": "30",
|
||||
"kind": "VARIABLE",
|
||||
"binding": {
|
||||
"endPosition": "26",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "idx",
|
||||
"startPosition": "23"
|
||||
},
|
||||
"startPosition": "19",
|
||||
"initializer": {
|
||||
"endPosition": "30",
|
||||
"kind": "NUMBER_LITERAL",
|
||||
"value": "0",
|
||||
"startPosition": "29"
|
||||
}
|
||||
},
|
||||
{
|
||||
"condition": {
|
||||
"leftOperand": {
|
||||
"endPosition": "43",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "idx",
|
||||
"startPosition": "40"
|
||||
},
|
||||
"endPosition": "47",
|
||||
"kind": "LESS_THAN",
|
||||
"rightOperand": {
|
||||
"endPosition": "47",
|
||||
"kind": "NUMBER_LITERAL",
|
||||
"value": "3",
|
||||
"startPosition": "46"
|
||||
},
|
||||
"startPosition": "40"
|
||||
},
|
||||
"endPosition": "65",
|
||||
"kind": "WHILE_LOOP",
|
||||
"statement": {
|
||||
"expression": {
|
||||
"expression": {
|
||||
"expression": {
|
||||
"endPosition": "62",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "idx",
|
||||
"startPosition": "59"
|
||||
},
|
||||
"endPosition": "64",
|
||||
"kind": "POSTFIX_INCREMENT",
|
||||
"startPosition": "59"
|
||||
},
|
||||
"endPosition": "64",
|
||||
"kind": "YIELD",
|
||||
"startPosition": "53"
|
||||
},
|
||||
"endPosition": "64",
|
||||
"kind": "EXPRESSION_STATEMENT",
|
||||
"startPosition": "53"
|
||||
},
|
||||
"startPosition": "34"
|
||||
}
|
||||
],
|
||||
"startPosition": "15"
|
||||
},
|
||||
"strict": "false",
|
||||
"startPosition": "1",
|
||||
"parameters": []
|
||||
},
|
||||
{
|
||||
"endPosition": "120",
|
||||
"kind": "VARIABLE",
|
||||
"binding": {
|
||||
"endPosition": "76",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "obj",
|
||||
"startPosition": "73"
|
||||
},
|
||||
"startPosition": "69",
|
||||
"initializer": {
|
||||
"endPosition": "120",
|
||||
"kind": "OBJECT_LITERAL",
|
||||
"startPosition": "79",
|
||||
"properties": [
|
||||
{
|
||||
"getter": "null",
|
||||
"endPosition": "118",
|
||||
"kind": "PROPERTY",
|
||||
"setter": "null",
|
||||
"value": {
|
||||
"endPosition": "95",
|
||||
"kind": "FUNCTION_EXPRESSION",
|
||||
"name": {
|
||||
"endPosition": "87",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "q",
|
||||
"startPosition": "85"
|
||||
},
|
||||
"generator": "true",
|
||||
"body": {
|
||||
"endPosition": "112",
|
||||
"kind": "BLOCK",
|
||||
"statements": [
|
||||
{
|
||||
"expression": {
|
||||
"expression": {
|
||||
"endPosition": "111",
|
||||
"kind": "NUMBER_LITERAL",
|
||||
"value": "1",
|
||||
"startPosition": "110"
|
||||
},
|
||||
"endPosition": "111",
|
||||
"kind": "YIELD",
|
||||
"startPosition": "104"
|
||||
},
|
||||
"endPosition": "111",
|
||||
"kind": "EXPRESSION_STATEMENT",
|
||||
"startPosition": "104"
|
||||
}
|
||||
],
|
||||
"startPosition": "95"
|
||||
},
|
||||
"strict": "false",
|
||||
"startPosition": "95",
|
||||
"parameters": [
|
||||
{
|
||||
"endPosition": "90",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "x",
|
||||
"startPosition": "89"
|
||||
},
|
||||
{
|
||||
"endPosition": "93",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "y",
|
||||
"startPosition": "92"
|
||||
}
|
||||
]
|
||||
},
|
||||
"startPosition": "85",
|
||||
"key": {
|
||||
"endPosition": "87",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "q",
|
||||
"startPosition": "85"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"endPosition": "250",
|
||||
"kind": "VARIABLE",
|
||||
"binding": {
|
||||
"endPosition": "128",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "f",
|
||||
"startPosition": "127"
|
||||
},
|
||||
"startPosition": "123",
|
||||
"initializer": {
|
||||
"endPosition": "250",
|
||||
"kind": "OBJECT_LITERAL",
|
||||
"startPosition": "131",
|
||||
"properties": [
|
||||
{
|
||||
"getter": "null",
|
||||
"computed": "true",
|
||||
"endPosition": "248",
|
||||
"kind": "PROPERTY",
|
||||
"setter": "null",
|
||||
"value": {
|
||||
"endPosition": "168",
|
||||
"kind": "FUNCTION_EXPRESSION",
|
||||
"name": "null",
|
||||
"generator": "true",
|
||||
"body": {
|
||||
"endPosition": "242",
|
||||
"kind": "BLOCK",
|
||||
"statements": [
|
||||
{
|
||||
"endPosition": "189",
|
||||
"kind": "VARIABLE",
|
||||
"binding": {
|
||||
"endPosition": "185",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "cur",
|
||||
"startPosition": "182"
|
||||
},
|
||||
"startPosition": "178",
|
||||
"initializer": {
|
||||
"endPosition": "189",
|
||||
"kind": "NUMBER_LITERAL",
|
||||
"value": "1",
|
||||
"startPosition": "188"
|
||||
}
|
||||
},
|
||||
{
|
||||
"condition": "null",
|
||||
"endPosition": "242",
|
||||
"kind": "FOR_LOOP",
|
||||
"statement": {
|
||||
"endPosition": "242",
|
||||
"kind": "BLOCK",
|
||||
"statements": [
|
||||
{
|
||||
"expression": {
|
||||
"expression": {
|
||||
"endPosition": "231",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "cur",
|
||||
"startPosition": "228"
|
||||
},
|
||||
"endPosition": "231",
|
||||
"kind": "YIELD",
|
||||
"startPosition": "222"
|
||||
},
|
||||
"endPosition": "231",
|
||||
"kind": "EXPRESSION_STATEMENT",
|
||||
"startPosition": "222"
|
||||
}
|
||||
],
|
||||
"startPosition": "208"
|
||||
},
|
||||
"update": "null",
|
||||
"startPosition": "199",
|
||||
"initializer": "null"
|
||||
}
|
||||
],
|
||||
"startPosition": "168"
|
||||
},
|
||||
"strict": "false",
|
||||
"startPosition": "168",
|
||||
"parameters": []
|
||||
},
|
||||
"startPosition": "137",
|
||||
"key": {
|
||||
"identifier": "iterator",
|
||||
"expression": {
|
||||
"endPosition": "144",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "Symbol",
|
||||
"startPosition": "138"
|
||||
},
|
||||
"endPosition": "153",
|
||||
"kind": "MEMBER_SELECT",
|
||||
"startPosition": "138"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
45
nashorn/test/script/nosecurity/treeapi/let.js
Normal file
45
nashorn/test/script/nosecurity/treeapi/let.js
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests to check representation of ES6 lets.
|
||||
*
|
||||
* @test
|
||||
* @option -scripting
|
||||
* @run
|
||||
*/
|
||||
|
||||
load(__DIR__ + "utils.js")
|
||||
|
||||
var code = <<EOF
|
||||
|
||||
let x = 3;
|
||||
|
||||
EOF
|
||||
|
||||
parse("let.js", code, "--language=es6", new (Java.extend(visitor_es6, {
|
||||
visitVariable : function (node, obj) {
|
||||
obj.push(convert(node))
|
||||
}
|
||||
})))
|
||||
|
20
nashorn/test/script/nosecurity/treeapi/let.js.EXPECTED
Normal file
20
nashorn/test/script/nosecurity/treeapi/let.js.EXPECTED
Normal file
@ -0,0 +1,20 @@
|
||||
[
|
||||
{
|
||||
"endPosition": "10",
|
||||
"kind": "VARIABLE",
|
||||
"binding": {
|
||||
"endPosition": "6",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "x",
|
||||
"startPosition": "5"
|
||||
},
|
||||
"let": "true",
|
||||
"startPosition": "1",
|
||||
"initializer": {
|
||||
"endPosition": "10",
|
||||
"kind": "NUMBER_LITERAL",
|
||||
"value": "3",
|
||||
"startPosition": "9"
|
||||
}
|
||||
}
|
||||
]
|
@ -28,6 +28,7 @@
|
||||
"expression": {
|
||||
"endPosition": "34",
|
||||
"kind": "IDENTIFIER",
|
||||
"this": "true",
|
||||
"name": "this",
|
||||
"startPosition": "30"
|
||||
},
|
||||
@ -47,4 +48,4 @@
|
||||
"kind": "MEMBER_SELECT",
|
||||
"startPosition": "40"
|
||||
}
|
||||
]
|
||||
]
|
||||
|
43
nashorn/test/script/nosecurity/treeapi/modules.js
Normal file
43
nashorn/test/script/nosecurity/treeapi/modules.js
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests to check representation of ES6 modules.
|
||||
*
|
||||
* @test
|
||||
* @option -scripting
|
||||
* @run
|
||||
*/
|
||||
|
||||
load(__DIR__ + "utils.js")
|
||||
|
||||
var code = <<EOF
|
||||
|
||||
import myDef, * as myMod from "my-mod";
|
||||
|
||||
export function func() {}
|
||||
|
||||
EOF
|
||||
|
||||
var mod = parseModule("foo", code);
|
||||
print(JSON.stringify(convert(mod), null, 2))
|
82
nashorn/test/script/nosecurity/treeapi/modules.js.EXPECTED
Normal file
82
nashorn/test/script/nosecurity/treeapi/modules.js.EXPECTED
Normal file
@ -0,0 +1,82 @@
|
||||
{
|
||||
"endPosition": "0",
|
||||
"kind": "COMPILATION_UNIT",
|
||||
"module": {
|
||||
"indirectExportEntries": [],
|
||||
"endPosition": "0",
|
||||
"kind": "MODULE",
|
||||
"localExportEntries": [
|
||||
{
|
||||
"localName": {
|
||||
"endPosition": "62",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "func",
|
||||
"startPosition": "58"
|
||||
},
|
||||
"endPosition": "67",
|
||||
"kind": "EXPORT_ENTRY",
|
||||
"moduleRequest": "null",
|
||||
"exportName": {
|
||||
"endPosition": "62",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "func",
|
||||
"startPosition": "58"
|
||||
},
|
||||
"importName": "null",
|
||||
"startPosition": "49"
|
||||
}
|
||||
],
|
||||
"starExportEntries": [],
|
||||
"startPosition": "0",
|
||||
"importEntries": [
|
||||
{
|
||||
"localName": {
|
||||
"endPosition": "25",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "myMod",
|
||||
"startPosition": "20"
|
||||
},
|
||||
"endPosition": "38",
|
||||
"kind": "IMPORT_ENTRY",
|
||||
"moduleRequest": {
|
||||
"endPosition": "30",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "my-mod",
|
||||
"startPosition": "32"
|
||||
},
|
||||
"importName": {
|
||||
"star": "true",
|
||||
"endPosition": "14",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "*",
|
||||
"startPosition": "15"
|
||||
},
|
||||
"startPosition": "1"
|
||||
}
|
||||
]
|
||||
},
|
||||
"sourceElements": [
|
||||
{
|
||||
"endPosition": "67",
|
||||
"kind": "FUNCTION",
|
||||
"name": {
|
||||
"endPosition": "62",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "func",
|
||||
"startPosition": "58"
|
||||
},
|
||||
"body": {
|
||||
"endPosition": "66",
|
||||
"kind": "BLOCK",
|
||||
"statements": [],
|
||||
"startPosition": "65"
|
||||
},
|
||||
"strict": "true",
|
||||
"startPosition": "49",
|
||||
"parameters": []
|
||||
}
|
||||
],
|
||||
"sourceName": "foo",
|
||||
"strict": "true",
|
||||
"startPosition": "0"
|
||||
}
|
@ -117,4 +117,4 @@
|
||||
"kind": "NEW",
|
||||
"startPosition": "59"
|
||||
}
|
||||
]
|
||||
]
|
||||
|
@ -226,6 +226,7 @@
|
||||
"expression": {
|
||||
"endPosition": "163",
|
||||
"kind": "IDENTIFIER",
|
||||
"this": "true",
|
||||
"name": "this",
|
||||
"startPosition": "159"
|
||||
},
|
||||
@ -269,6 +270,7 @@
|
||||
"expression": {
|
||||
"endPosition": "191",
|
||||
"kind": "IDENTIFIER",
|
||||
"this": "true",
|
||||
"name": "this",
|
||||
"startPosition": "187"
|
||||
},
|
||||
@ -307,4 +309,4 @@
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
]
|
||||
|
@ -89,4 +89,4 @@
|
||||
"startPosition": "64"
|
||||
}
|
||||
}
|
||||
]
|
||||
]
|
||||
|
53
nashorn/test/script/nosecurity/treeapi/rest.js
Normal file
53
nashorn/test/script/nosecurity/treeapi/rest.js
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests to check representation of ES6 rest arguments.
|
||||
*
|
||||
* @test
|
||||
* @option -scripting
|
||||
* @run
|
||||
*/
|
||||
|
||||
load(__DIR__ + "utils.js")
|
||||
|
||||
var code = <<EOF
|
||||
|
||||
function func(a, ...all) {}
|
||||
|
||||
function bar(...allargs) {}
|
||||
|
||||
var f = function(x, ...extra) {}
|
||||
var f2 = function(...rest) {}
|
||||
|
||||
EOF
|
||||
|
||||
parse("rest.js", code, "--language=es6", new (Java.extend(visitor_es6, {
|
||||
visitFunctionDeclaration: function (node, obj) {
|
||||
obj.push(convert(node))
|
||||
},
|
||||
visitVariable: function (node, obj) {
|
||||
obj.push(convert(node))
|
||||
}
|
||||
})))
|
||||
|
134
nashorn/test/script/nosecurity/treeapi/rest.js.EXPECTED
Normal file
134
nashorn/test/script/nosecurity/treeapi/rest.js.EXPECTED
Normal file
@ -0,0 +1,134 @@
|
||||
[
|
||||
{
|
||||
"endPosition": "28",
|
||||
"kind": "FUNCTION",
|
||||
"name": {
|
||||
"endPosition": "14",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "func",
|
||||
"startPosition": "10"
|
||||
},
|
||||
"body": {
|
||||
"endPosition": "27",
|
||||
"kind": "BLOCK",
|
||||
"statements": [],
|
||||
"startPosition": "26"
|
||||
},
|
||||
"strict": "false",
|
||||
"startPosition": "1",
|
||||
"parameters": [
|
||||
{
|
||||
"endPosition": "16",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "a",
|
||||
"startPosition": "15"
|
||||
},
|
||||
{
|
||||
"endPosition": "24",
|
||||
"restParameter": "true",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "all",
|
||||
"startPosition": "21"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"endPosition": "57",
|
||||
"kind": "FUNCTION",
|
||||
"name": {
|
||||
"endPosition": "42",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "bar",
|
||||
"startPosition": "39"
|
||||
},
|
||||
"body": {
|
||||
"endPosition": "56",
|
||||
"kind": "BLOCK",
|
||||
"statements": [],
|
||||
"startPosition": "55"
|
||||
},
|
||||
"strict": "false",
|
||||
"startPosition": "30",
|
||||
"parameters": [
|
||||
{
|
||||
"endPosition": "53",
|
||||
"restParameter": "true",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "allargs",
|
||||
"startPosition": "46"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"endPosition": "91",
|
||||
"kind": "VARIABLE",
|
||||
"binding": {
|
||||
"endPosition": "64",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "f",
|
||||
"startPosition": "63"
|
||||
},
|
||||
"startPosition": "59",
|
||||
"initializer": {
|
||||
"endPosition": "89",
|
||||
"kind": "FUNCTION_EXPRESSION",
|
||||
"name": "null",
|
||||
"body": {
|
||||
"endPosition": "90",
|
||||
"kind": "BLOCK",
|
||||
"statements": [],
|
||||
"startPosition": "89"
|
||||
},
|
||||
"strict": "false",
|
||||
"startPosition": "89",
|
||||
"parameters": [
|
||||
{
|
||||
"endPosition": "77",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "x",
|
||||
"startPosition": "76"
|
||||
},
|
||||
{
|
||||
"endPosition": "87",
|
||||
"restParameter": "true",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "extra",
|
||||
"startPosition": "82"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"endPosition": "121",
|
||||
"kind": "VARIABLE",
|
||||
"binding": {
|
||||
"endPosition": "98",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "f2",
|
||||
"startPosition": "96"
|
||||
},
|
||||
"startPosition": "92",
|
||||
"initializer": {
|
||||
"endPosition": "119",
|
||||
"kind": "FUNCTION_EXPRESSION",
|
||||
"name": "null",
|
||||
"body": {
|
||||
"endPosition": "120",
|
||||
"kind": "BLOCK",
|
||||
"statements": [],
|
||||
"startPosition": "119"
|
||||
},
|
||||
"strict": "false",
|
||||
"startPosition": "119",
|
||||
"parameters": [
|
||||
{
|
||||
"endPosition": "117",
|
||||
"restParameter": "true",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "rest",
|
||||
"startPosition": "113"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
@ -59,4 +59,4 @@
|
||||
"kind": "RETURN",
|
||||
"startPosition": "207"
|
||||
}
|
||||
]
|
||||
]
|
||||
|
53
nashorn/test/script/nosecurity/treeapi/spread.js
Normal file
53
nashorn/test/script/nosecurity/treeapi/spread.js
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests to check representation of ES6 spread arguments.
|
||||
*
|
||||
* @test
|
||||
* @option -scripting
|
||||
* @run
|
||||
*/
|
||||
|
||||
load(__DIR__ + "utils.js")
|
||||
|
||||
var code = <<EOF
|
||||
|
||||
foo(a, ...b);
|
||||
|
||||
bar(3, ...[3, 5, 546]);
|
||||
|
||||
var arr = [3, ...a, 5];
|
||||
var arr2 = [4, ...[5, 6], 78];
|
||||
|
||||
EOF
|
||||
|
||||
parse("spread.js", code, "--language=es6", new (Java.extend(visitor_es6, {
|
||||
visitFunctionCall: function (node, obj) {
|
||||
obj.push(convert(node))
|
||||
},
|
||||
visitVariable: function (node, obj) {
|
||||
obj.push(convert(node))
|
||||
}
|
||||
})))
|
||||
|
176
nashorn/test/script/nosecurity/treeapi/spread.js.EXPECTED
Normal file
176
nashorn/test/script/nosecurity/treeapi/spread.js.EXPECTED
Normal file
@ -0,0 +1,176 @@
|
||||
[
|
||||
{
|
||||
"endPosition": "13",
|
||||
"kind": "FUNCTION_INVOCATION",
|
||||
"functionSelect": {
|
||||
"endPosition": "4",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "foo",
|
||||
"startPosition": "1"
|
||||
},
|
||||
"arguments": [
|
||||
{
|
||||
"endPosition": "6",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "a",
|
||||
"startPosition": "5"
|
||||
},
|
||||
{
|
||||
"expression": {
|
||||
"endPosition": "12",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "b",
|
||||
"startPosition": "11"
|
||||
},
|
||||
"endPosition": "12",
|
||||
"kind": "SPREAD",
|
||||
"startPosition": "8"
|
||||
}
|
||||
],
|
||||
"startPosition": "1"
|
||||
},
|
||||
{
|
||||
"endPosition": "38",
|
||||
"kind": "FUNCTION_INVOCATION",
|
||||
"functionSelect": {
|
||||
"endPosition": "19",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "bar",
|
||||
"startPosition": "16"
|
||||
},
|
||||
"arguments": [
|
||||
{
|
||||
"endPosition": "21",
|
||||
"kind": "NUMBER_LITERAL",
|
||||
"value": "3",
|
||||
"startPosition": "20"
|
||||
},
|
||||
{
|
||||
"expression": {
|
||||
"endPosition": "37",
|
||||
"kind": "ARRAY_LITERAL",
|
||||
"elements": [
|
||||
{
|
||||
"endPosition": "28",
|
||||
"kind": "NUMBER_LITERAL",
|
||||
"value": "3",
|
||||
"startPosition": "27"
|
||||
},
|
||||
{
|
||||
"endPosition": "31",
|
||||
"kind": "NUMBER_LITERAL",
|
||||
"value": "5",
|
||||
"startPosition": "30"
|
||||
},
|
||||
{
|
||||
"endPosition": "36",
|
||||
"kind": "NUMBER_LITERAL",
|
||||
"value": "546",
|
||||
"startPosition": "33"
|
||||
}
|
||||
],
|
||||
"startPosition": "26"
|
||||
},
|
||||
"endPosition": "37",
|
||||
"kind": "SPREAD",
|
||||
"startPosition": "23"
|
||||
}
|
||||
],
|
||||
"startPosition": "16"
|
||||
},
|
||||
{
|
||||
"endPosition": "63",
|
||||
"kind": "VARIABLE",
|
||||
"binding": {
|
||||
"endPosition": "48",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "arr",
|
||||
"startPosition": "45"
|
||||
},
|
||||
"startPosition": "41",
|
||||
"initializer": {
|
||||
"endPosition": "63",
|
||||
"kind": "ARRAY_LITERAL",
|
||||
"elements": [
|
||||
{
|
||||
"endPosition": "53",
|
||||
"kind": "NUMBER_LITERAL",
|
||||
"value": "3",
|
||||
"startPosition": "52"
|
||||
},
|
||||
{
|
||||
"expression": {
|
||||
"endPosition": "59",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "a",
|
||||
"startPosition": "58"
|
||||
},
|
||||
"endPosition": "59",
|
||||
"kind": "SPREAD",
|
||||
"startPosition": "55"
|
||||
},
|
||||
{
|
||||
"endPosition": "62",
|
||||
"kind": "NUMBER_LITERAL",
|
||||
"value": "5",
|
||||
"startPosition": "61"
|
||||
}
|
||||
],
|
||||
"startPosition": "51"
|
||||
}
|
||||
},
|
||||
{
|
||||
"endPosition": "94",
|
||||
"kind": "VARIABLE",
|
||||
"binding": {
|
||||
"endPosition": "73",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "arr2",
|
||||
"startPosition": "69"
|
||||
},
|
||||
"startPosition": "65",
|
||||
"initializer": {
|
||||
"endPosition": "94",
|
||||
"kind": "ARRAY_LITERAL",
|
||||
"elements": [
|
||||
{
|
||||
"endPosition": "78",
|
||||
"kind": "NUMBER_LITERAL",
|
||||
"value": "4",
|
||||
"startPosition": "77"
|
||||
},
|
||||
{
|
||||
"expression": {
|
||||
"endPosition": "89",
|
||||
"kind": "ARRAY_LITERAL",
|
||||
"elements": [
|
||||
{
|
||||
"endPosition": "85",
|
||||
"kind": "NUMBER_LITERAL",
|
||||
"value": "5",
|
||||
"startPosition": "84"
|
||||
},
|
||||
{
|
||||
"endPosition": "88",
|
||||
"kind": "NUMBER_LITERAL",
|
||||
"value": "6",
|
||||
"startPosition": "87"
|
||||
}
|
||||
],
|
||||
"startPosition": "83"
|
||||
},
|
||||
"endPosition": "89",
|
||||
"kind": "SPREAD",
|
||||
"startPosition": "80"
|
||||
},
|
||||
{
|
||||
"endPosition": "93",
|
||||
"kind": "NUMBER_LITERAL",
|
||||
"value": "78",
|
||||
"startPosition": "91"
|
||||
}
|
||||
],
|
||||
"startPosition": "76"
|
||||
}
|
||||
}
|
||||
]
|
40
nashorn/test/script/nosecurity/treeapi/template_literal.js
Normal file
40
nashorn/test/script/nosecurity/treeapi/template_literal.js
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests to check representation of ES6 template literal.
|
||||
*
|
||||
* @test
|
||||
* @run
|
||||
*/
|
||||
|
||||
load(__DIR__ + "utils.js")
|
||||
|
||||
var code = "`your name is ${name} and you work for ${company}`"
|
||||
|
||||
parse("template_literal.js", code, "--language=es6", new (Java.extend(visitor_es6, {
|
||||
visitTemplateLiteral : function (node, obj) {
|
||||
obj.push(convert(node))
|
||||
}
|
||||
})))
|
||||
|
@ -0,0 +1,39 @@
|
||||
[
|
||||
{
|
||||
"endPosition": "49",
|
||||
"kind": "TEMPLATE_LITERAL",
|
||||
"expressions": [
|
||||
{
|
||||
"endPosition": "14",
|
||||
"kind": "STRING_LITERAL",
|
||||
"value": "your name is ",
|
||||
"startPosition": "1"
|
||||
},
|
||||
{
|
||||
"endPosition": "20",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "name",
|
||||
"startPosition": "16"
|
||||
},
|
||||
{
|
||||
"endPosition": "39",
|
||||
"kind": "STRING_LITERAL",
|
||||
"value": " and you work for ",
|
||||
"startPosition": "21"
|
||||
},
|
||||
{
|
||||
"endPosition": "48",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "company",
|
||||
"startPosition": "41"
|
||||
},
|
||||
{
|
||||
"endPosition": "49",
|
||||
"kind": "STRING_LITERAL",
|
||||
"value": "",
|
||||
"startPosition": "49"
|
||||
}
|
||||
],
|
||||
"startPosition": "1"
|
||||
}
|
||||
]
|
@ -30,17 +30,42 @@ var parser = Java.type('jdk.nashorn.api.tree.Parser');
|
||||
var tree = Java.type('jdk.nashorn.api.tree.Tree');
|
||||
var list = Java.type('java.util.List');
|
||||
var visitor = Java.type('jdk.nashorn.api.tree.SimpleTreeVisitorES5_1');
|
||||
var visitor_es6 = Java.type('jdk.nashorn.api.tree.SimpleTreeVisitorES6');
|
||||
var file = Java.type('java.io.File')
|
||||
var cls = Java.type('java.lang.Class')
|
||||
|
||||
function convert (value) {
|
||||
if (!value) {
|
||||
if (!value || typeof(value) != 'object') {
|
||||
return value;
|
||||
}
|
||||
var obj = Object.bindProperties({}, value)
|
||||
var result = {}
|
||||
for (var i in obj) {
|
||||
if (i == "lineMap") {
|
||||
continue;
|
||||
}
|
||||
|
||||
var val = obj[i]
|
||||
// skip these ES6 specific properties to reduce noise
|
||||
// in the output - unless there were set to true
|
||||
if (typeof(val) == 'boolean' && val == false) {
|
||||
switch (i) {
|
||||
case "computed":
|
||||
case "static":
|
||||
case "restParameter":
|
||||
case "this":
|
||||
case "super":
|
||||
case "star":
|
||||
case "default":
|
||||
case "starDefaultStar":
|
||||
case "arrow":
|
||||
case "generator":
|
||||
case "let":
|
||||
case "const":
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof(val) == 'object') {
|
||||
if (val instanceof cls) {
|
||||
continue;
|
||||
@ -72,6 +97,9 @@ function parse(name, code, args, visitor, listener) {
|
||||
print(JSON.stringify(results, null, 2))
|
||||
}
|
||||
|
||||
function parseModule(name, code) {
|
||||
return parser.create("--es6-module").parse(name, code, null);
|
||||
}
|
||||
|
||||
function parseDiagnostic (code, args) {
|
||||
var messages = new Array()
|
||||
@ -79,4 +107,4 @@ function parseDiagnostic (code, args) {
|
||||
messages.push(convert(message))
|
||||
})
|
||||
print(JSON.stringify(messages, null, 2).replace(/\\r/g, ''))
|
||||
}
|
||||
}
|
||||
|
@ -2,15 +2,25 @@
|
||||
{
|
||||
"endPosition": "6",
|
||||
"kind": "VARIABLE",
|
||||
"name": "a",
|
||||
"startPosition": "5",
|
||||
"binding": {
|
||||
"endPosition": "6",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "a",
|
||||
"startPosition": "5"
|
||||
},
|
||||
"startPosition": "1",
|
||||
"initializer": "null"
|
||||
},
|
||||
{
|
||||
"endPosition": "16",
|
||||
"kind": "VARIABLE",
|
||||
"name": "x",
|
||||
"startPosition": "11",
|
||||
"binding": {
|
||||
"endPosition": "12",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "x",
|
||||
"startPosition": "11"
|
||||
},
|
||||
"startPosition": "7",
|
||||
"initializer": {
|
||||
"endPosition": "16",
|
||||
"kind": "NUMBER_LITERAL",
|
||||
@ -21,15 +31,25 @@
|
||||
{
|
||||
"endPosition": "24",
|
||||
"kind": "VARIABLE",
|
||||
"name": "x23",
|
||||
"startPosition": "21",
|
||||
"binding": {
|
||||
"endPosition": "24",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "x23",
|
||||
"startPosition": "21"
|
||||
},
|
||||
"startPosition": "17",
|
||||
"initializer": "null"
|
||||
},
|
||||
{
|
||||
"endPosition": "32",
|
||||
"kind": "VARIABLE",
|
||||
"name": "$y",
|
||||
"startPosition": "26",
|
||||
"binding": {
|
||||
"endPosition": "28",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "$y",
|
||||
"startPosition": "26"
|
||||
},
|
||||
"startPosition": "17",
|
||||
"initializer": {
|
||||
"endPosition": "32",
|
||||
"kind": "NUMBER_LITERAL",
|
||||
@ -40,8 +60,13 @@
|
||||
{
|
||||
"endPosition": "36",
|
||||
"kind": "VARIABLE",
|
||||
"name": "_z",
|
||||
"startPosition": "34",
|
||||
"binding": {
|
||||
"endPosition": "36",
|
||||
"kind": "IDENTIFIER",
|
||||
"name": "_z",
|
||||
"startPosition": "34"
|
||||
},
|
||||
"startPosition": "17",
|
||||
"initializer": "null"
|
||||
}
|
||||
]
|
||||
]
|
||||
|
@ -114,6 +114,7 @@
|
||||
"expression": {
|
||||
"endPosition": "76",
|
||||
"kind": "IDENTIFIER",
|
||||
"this": "true",
|
||||
"name": "this",
|
||||
"startPosition": "72"
|
||||
},
|
||||
@ -140,4 +141,4 @@
|
||||
},
|
||||
"startPosition": "52"
|
||||
}
|
||||
]
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user