├── .gitattributes ├── .github └── workflows │ └── check.yml ├── .gitignore ├── .gitmodules ├── LICENSE ├── README.md ├── build-scripts ├── .eslintrc.js ├── package-lock.json ├── package.json └── scripts │ ├── build │ ├── ast-path.js │ ├── ast.js │ ├── branch.js │ ├── branchIterator.js │ ├── deserializer.js │ ├── director.js │ ├── reducer-clone.js │ ├── reducer-lazy-clone.js │ ├── reducer-monoidal.js │ ├── reducer-thunked.js │ ├── reducer-wrapped.js │ ├── reducer.js │ ├── serializer.js │ ├── template-structured-reducer.js │ └── thunkify.js │ └── lib │ ├── clone-utilities.js │ ├── find-max-super.js │ ├── out-dir.js │ ├── unions-to-interfaces.js │ └── utilities.js ├── build.sh ├── generated-sources └── main │ └── java │ └── com │ └── shapesecurity │ └── shift │ └── es2018 │ ├── ast │ ├── ArrayAssignmentTarget.java │ ├── ArrayBinding.java │ ├── ArrayExpression.java │ ├── ArrowExpression.java │ ├── AssignmentExpression.java │ ├── AssignmentTarget.java │ ├── AssignmentTargetAssignmentTargetWithDefault.java │ ├── AssignmentTargetIdentifier.java │ ├── AssignmentTargetPattern.java │ ├── AssignmentTargetProperty.java │ ├── AssignmentTargetPropertyIdentifier.java │ ├── AssignmentTargetPropertyProperty.java │ ├── AssignmentTargetWithDefault.java │ ├── AwaitExpression.java │ ├── BinaryExpression.java │ ├── Binding.java │ ├── BindingBindingWithDefault.java │ ├── BindingIdentifier.java │ ├── BindingPattern.java │ ├── BindingProperty.java │ ├── BindingPropertyIdentifier.java │ ├── BindingPropertyProperty.java │ ├── BindingWithDefault.java │ ├── Block.java │ ├── BlockStatement.java │ ├── BreakStatement.java │ ├── CallExpression.java │ ├── CatchClause.java │ ├── Class.java │ ├── ClassDeclaration.java │ ├── ClassElement.java │ ├── ClassExpression.java │ ├── CompoundAssignmentExpression.java │ ├── ComputedMemberAssignmentTarget.java │ ├── ComputedMemberExpression.java │ ├── ComputedPropertyName.java │ ├── ConditionalExpression.java │ ├── ContinueStatement.java │ ├── DataProperty.java │ ├── DebuggerStatement.java │ ├── Directive.java │ ├── DoWhileStatement.java │ ├── EmptyStatement.java │ ├── Export.java │ ├── ExportAllFrom.java │ ├── ExportDeclaration.java │ ├── ExportDefault.java │ ├── ExportFrom.java │ ├── ExportFromSpecifier.java │ ├── ExportLocalSpecifier.java │ ├── ExportLocals.java │ ├── Expression.java │ ├── ExpressionStatement.java │ ├── ExpressionSuper.java │ ├── ExpressionTemplateElement.java │ ├── ForAwaitStatement.java │ ├── ForInStatement.java │ ├── ForOfStatement.java │ ├── ForStatement.java │ ├── FormalParameters.java │ ├── Function.java │ ├── FunctionBody.java │ ├── FunctionBodyExpression.java │ ├── FunctionDeclaration.java │ ├── FunctionDeclarationClassDeclarationExpression.java │ ├── FunctionDeclarationClassDeclarationVariableDeclaration.java │ ├── FunctionExpression.java │ ├── Getter.java │ ├── IdentifierExpression.java │ ├── IfStatement.java │ ├── Import.java │ ├── ImportDeclaration.java │ ├── ImportDeclarationExportDeclarationStatement.java │ ├── ImportNamespace.java │ ├── ImportSpecifier.java │ ├── IterationStatement.java │ ├── LabeledStatement.java │ ├── LiteralBooleanExpression.java │ ├── LiteralInfinityExpression.java │ ├── LiteralNullExpression.java │ ├── LiteralNumericExpression.java │ ├── LiteralRegExpExpression.java │ ├── LiteralStringExpression.java │ ├── MemberAssignmentTarget.java │ ├── MemberExpression.java │ ├── Method.java │ ├── MethodDefinition.java │ ├── Module.java │ ├── NamedObjectProperty.java │ ├── NewExpression.java │ ├── NewTargetExpression.java │ ├── Node.java │ ├── ObjectAssignmentTarget.java │ ├── ObjectBinding.java │ ├── ObjectExpression.java │ ├── ObjectProperty.java │ ├── Parameter.java │ ├── Program.java │ ├── PropertyName.java │ ├── ReturnStatement.java │ ├── Script.java │ ├── Setter.java │ ├── ShorthandProperty.java │ ├── SimpleAssignmentTarget.java │ ├── SpreadElement.java │ ├── SpreadElementExpression.java │ ├── SpreadProperty.java │ ├── Statement.java │ ├── StaticMemberAssignmentTarget.java │ ├── StaticMemberExpression.java │ ├── StaticPropertyName.java │ ├── Super.java │ ├── SwitchCase.java │ ├── SwitchDefault.java │ ├── SwitchStatement.java │ ├── SwitchStatementWithDefault.java │ ├── TemplateElement.java │ ├── TemplateExpression.java │ ├── ThisExpression.java │ ├── ThrowStatement.java │ ├── TryCatchStatement.java │ ├── TryFinallyStatement.java │ ├── UnaryExpression.java │ ├── UpdateExpression.java │ ├── VariableDeclaration.java │ ├── VariableDeclarationAssignmentTarget.java │ ├── VariableDeclarationExpression.java │ ├── VariableDeclarationStatement.java │ ├── VariableDeclarator.java │ ├── VariableReference.java │ ├── WhileStatement.java │ ├── WithStatement.java │ ├── YieldExpression.java │ └── YieldGeneratorExpression.java │ ├── astpath │ └── ASTPath.java │ ├── path │ ├── Branch.java │ └── BranchIterator.java │ ├── reducer │ ├── Director.java │ ├── LazyReconstructingReducer.java │ ├── MonoidalReducer.java │ ├── ReconstructingReducer.java │ ├── Reducer.java │ ├── Thunked.java │ ├── ThunkedDirector.java │ ├── ThunkedReducer.java │ └── WrappedReducer.java │ ├── serialization │ ├── Deserializer.java │ └── Serializer.java │ └── template │ └── ReduceStructured.java ├── pom.xml ├── scripts └── make-unicode-regexen.js └── src ├── main └── java │ └── com │ └── shapesecurity │ └── shift │ └── es2018 │ ├── ast │ ├── VariableDeclarationKind.java │ └── operators │ │ ├── BinaryOperator.java │ │ ├── CompoundAssignmentOperator.java │ │ ├── Operator.java │ │ ├── Precedence.java │ │ ├── UnaryOperator.java │ │ └── UpdateOperator.java │ ├── astpath │ └── ObjectPath.java │ ├── codegen │ ├── CodeGen.java │ ├── CodeRep.java │ ├── CodeRepFactory.java │ ├── FormattedCodeRep.java │ ├── FormattedCodeRepFactory.java │ ├── PrettyCodeGen.java │ ├── README.md │ ├── TokenStream.java │ ├── WebSafeCodeGen.java │ └── location │ │ ├── CodeGenWithLocation.java │ │ ├── CodeRepWithLocation.java │ │ ├── LocationMeta.java │ │ └── TokenStreamWithLocation.java │ ├── fuzzer │ ├── Fuzzer.java │ └── GenCtx.java │ ├── minifier │ ├── ComposedRule.java │ ├── ExpansionRule.java │ ├── MinificationRule.java │ ├── Minifier.java │ ├── README.md │ ├── ReductionRule.java │ └── passes │ │ ├── expansion │ │ ├── ExpandBooleanLiterals.java │ │ ├── ReplaceStaticMemberAccessWithDynamicMemberAccess.java │ │ └── TopLevelExpressionWithProhibitedFirstToken.java │ │ └── reduction │ │ ├── FlattenBlocks.java │ │ ├── ReduceNestedIfStatements.java │ │ ├── RemoveEmptyBlocks.java │ │ ├── RemoveEmptyStatements.java │ │ ├── RemoveEmptyTrailingDefault.java │ │ ├── RemoveSingleStatementBlocks.java │ │ └── ReplaceWhileWithFor.java │ ├── parser │ ├── EarlyError.java │ ├── EarlyErrorChecker.java │ ├── EarlyErrorState.java │ ├── ErrorMessages.java │ ├── GenericParser.java │ ├── JsError.java │ ├── Located.java │ ├── Parser.java │ ├── ParserWithLocation.java │ ├── PatternAcceptor.java │ ├── README.md │ ├── SourceLocation.java │ ├── SourceRange.java │ ├── SourceSpan.java │ ├── Token.java │ ├── TokenClass.java │ ├── TokenType.java │ ├── Tokenizer.java │ ├── TokenizerState.java │ └── token │ │ ├── EOFToken.java │ │ ├── FalseLiteralToken.java │ │ ├── IdentifierLikeToken.java │ │ ├── IdentifierToken.java │ │ ├── KeywordToken.java │ │ ├── NullLiteralToken.java │ │ ├── NumericLiteralToken.java │ │ ├── PunctuatorToken.java │ │ ├── RegularExpressionLiteralToken.java │ │ ├── StringLiteralToken.java │ │ ├── TemplateToken.java │ │ └── TrueLiteralToken.java │ ├── path │ └── BranchGetter.java │ ├── reducer │ ├── ComposedMonoidalReducer.java │ ├── Flattener.java │ ├── MultiMonoidalReducer.java │ ├── StrictnessReducer.java │ └── disabled │ │ ├── CloneReducer.java │ │ ├── DirectorP.java │ │ ├── DirtyState.java │ │ ├── FixPointTransformer.java │ │ ├── LazyCloner.java │ │ ├── ReducerP.java │ │ ├── Transformer.java │ │ └── TransformerP.java │ ├── scope │ ├── Accessibility.java │ ├── Declaration.java │ ├── GlobalScope.java │ ├── README.md │ ├── Reference.java │ ├── Scope.java │ ├── ScopeAnalyzer.java │ ├── ScopeLookup.java │ ├── ScopeSerializer.java │ └── Variable.java │ ├── template │ ├── README.md │ └── Template.java │ ├── utils │ ├── D2A.java │ ├── Either3.java │ ├── Utils.java │ └── WithLocation.java │ └── validator │ ├── README.md │ ├── ValidationContext.java │ ├── ValidationError.java │ ├── ValidationErrorMessages.java │ └── Validator.java └── test ├── java └── com │ └── shapesecurity │ └── shift │ └── es2018 │ ├── Serialization │ ├── DeserializerTest.java │ └── SerializerTest.java │ ├── ast │ └── AstTest.java │ ├── astpath │ └── ASTPathTest.java │ ├── benchmark │ ├── BenchmarkTest.java │ └── D2ABenchmark.java │ ├── codegen │ ├── CodeGenTest.java │ └── WebSafeCodeGenTest.java │ ├── comparison │ └── ComparisonTest.java │ ├── fuzzer │ └── FuzzerTest.java │ ├── integration │ └── IntegrationTest.java │ ├── minifier │ └── MinifierTest.java │ ├── others │ ├── AstHelper.java │ ├── TestBase.java │ ├── TestReducer.java │ └── TestReducerWithPath.java │ ├── parser │ ├── API │ │ ├── APITest.java │ │ ├── ModuleTest.java │ │ └── ScriptTest.java │ ├── DirectiveTest.java │ ├── EarlyErrorsTest.java │ ├── FailuresTest.java │ ├── ParserTest.java │ ├── ParserTestCase.java │ ├── RangeCheckerReducer.java │ ├── declarations │ │ ├── ClassDeclarationTest.java │ │ ├── FunctionDeclarationTest.java │ │ ├── GeneratorDeclarationTest.java │ │ └── LexicalDeclarationTest.java │ ├── destructuring │ │ ├── assignment │ │ │ ├── ArrayAssignmentTargetTest.java │ │ │ └── ObjectAssignmentTargetTest.java │ │ └── binding_pattern │ │ │ ├── ArrayBindingTest.java │ │ │ ├── BindingIdentifierTest.java │ │ │ └── ObjectBindingTest.java │ ├── expressions │ │ ├── ArrayExpressionTest.java │ │ ├── ArrowExpressionTest.java │ │ ├── AssignmentExpressionTest.java │ │ ├── BinaryExpressionTest.java │ │ ├── CallExpressionTest.java │ │ ├── ClassExpressionTest.java │ │ ├── ComputedMemberExpressionTest.java │ │ ├── ConditionalExpressionTest.java │ │ ├── FunctionExpressionTest.java │ │ ├── GroupedExpressionTest.java │ │ ├── IdentifierExpressionTest.java │ │ ├── NewExpressionTest.java │ │ ├── NewTargetExpressionTest.java │ │ ├── ObjectExpressionTest.java │ │ ├── StaticMemberExpressionTest.java │ │ ├── SuperExpressionTest.java │ │ ├── TemplateExpressionTest.java │ │ ├── ThisExpressionTest.java │ │ ├── UnaryExpressionTest.java │ │ ├── UpdateExpressionTest.java │ │ ├── YieldExpressionTest.java │ │ ├── YieldGeneratorExpressionTest.java │ │ └── literals │ │ │ ├── LiteralInfinityExpressionTest.java │ │ │ ├── LiteralNullExpressionTest.java │ │ │ ├── LiteralNumericExpressionTest.java │ │ │ ├── LiteralRegExpExpressionTest.java │ │ │ └── LiteralStringExpressionTest.java │ ├── gecko │ │ ├── AsyncAwaitCoverInitTest.java │ │ ├── AsyncAwaitEarlyErrorsTest.java │ │ ├── AsyncAwaitMiscTest.java │ │ └── AsyncAwaitReflectTest.java │ ├── miscellaneous │ │ ├── AsyncAwaitTest.java │ │ ├── CommentsTest.java │ │ ├── EscapedKeywords.java │ │ ├── GroupingTest.java │ │ ├── IncompatibilitiesTest.java │ │ ├── InteractionsTest.java │ │ ├── LocationTest.java │ │ ├── SemicolonsTest.java │ │ ├── TrailingCommaTest.java │ │ └── WhitespaceTest.java │ ├── modules │ │ ├── ExportTest.java │ │ └── ImportTest.java │ ├── property_definitions │ │ ├── GeneratorMethodTest.java │ │ └── PropertyNameTest.java │ └── statements │ │ ├── BlockStatementTest.java │ │ ├── BreakStatementTest.java │ │ ├── ContinueStatementTest.java │ │ ├── DebuggerStatementTest.java │ │ ├── DoWhileStatementTest.java │ │ ├── EmptyStatementTest.java │ │ ├── ExpressionStatementTest.java │ │ ├── ForAwaitStatementTest.java │ │ ├── ForInStatementTest.java │ │ ├── ForOfStatementTest.java │ │ ├── ForStatementTest.java │ │ ├── IfStatementTest.java │ │ ├── LabeledStatementTest.java │ │ ├── ReturnStatementTest.java │ │ ├── SwitchStatementTest.java │ │ ├── SwitchStatementWithDefaultTest.java │ │ ├── ThrowStatementTest.java │ │ ├── TryCatchStatementTest.java │ │ ├── TryFinallyStatementTest.java │ │ ├── VariableDeclarationStatementTest.java │ │ ├── WhileStatementTest.java │ │ └── WithStatementTest.java │ ├── path │ ├── BranchGetterTest.java │ ├── BranchIteratorTest.java │ ├── EqualityTest.java │ └── ToStringTest.java │ ├── reducer │ ├── CloneReducerTest.java │ ├── CloneReducerTestCase.java │ ├── Counter.java │ ├── ReducerTest.java │ ├── VisitorTestCase.java │ └── disabled │ │ ├── LazyClonerTest.java │ │ └── TransformerTest.java │ ├── scope │ ├── ScopeLookupTest.java │ ├── ScopeSerializerTest.java │ ├── ScopeTest.java │ ├── VariableOrderingTest.java │ └── disabled │ │ └── ScopeTest.java │ ├── template │ ├── ApplyStructuredTemplateTest.java │ ├── ApplyTemplateTest.java │ └── FindNodesTest.java │ ├── test262 │ ├── Test262.java │ ├── Test262Info.java │ ├── expectations │ │ ├── BigIntNoLiterals.java │ │ ├── NumericSeperatorNoLiterals.java │ │ ├── Regexp.java │ │ └── XFailHelper.java │ └── parser │ │ ├── EarlyTest.java │ │ ├── FailTest.java │ │ ├── PassTest.java │ │ └── XFailHelper.java │ ├── utils │ └── D2ATest.java │ └── validator │ └── ValidatorTest.java └── resources └── libraries ├── angular-1.2.5.js ├── angular-1.2.5.min.js ├── angular-1.2.5.min.ugly.js ├── backbone-1.1.0.js ├── backbone-min-1.1.2.js ├── dojo-1.10.0.js ├── ember-1.7.0.js ├── everything-0.0.4.js ├── ga.js ├── jquery-1.9.1.js ├── jquery.min-2.1.1.js ├── jquery.mobile.min-1.4.3.js ├── knockout-v3.2.0.js ├── mootools-1.4.5.js ├── mootools-yui-compressed-1.5.0.js ├── prototype-1.7.2.0.js ├── qunit-v1.14.0.js ├── scriptaculous-1.9.0.js ├── swfobject-2.2.js ├── three.min-r67.js ├── underscore-1.5.2.js ├── webfont-1.5.3.js ├── yui-3.12.0.js └── yui-min-3.17.2.js /.gitattributes: -------------------------------------------------------------------------------- 1 | generates-source/ linguist-generated=true 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | out/ 2 | target/ 3 | .idea 4 | .project 5 | *.iml 6 | .classpath 7 | .settings/ 8 | **/node_modules/ 9 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "src/test/resources/test262-parser-tests"] 2 | path = src/test/resources/test262-parser-tests 3 | url = https://github.com/tc39/test262-parser-tests.git 4 | [submodule "src/test/resources/shift-parser-expectations"] 5 | path = src/test/resources/shift-parser-expectations 6 | url = https://github.com/shapesecurity/shift-parser-expectations.git 7 | [submodule "src/test/resources/test262"] 8 | path = src/test/resources/test262 9 | url = https://github.com/tc39/test262.git 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Shift Tools for Java 2 | ==================== 3 | 4 | ## About 5 | 6 | This project provides Java tooling around the [Shift AST format](https://github.com/shapesecurity/shift-spec). 7 | 8 | ## Generating code 9 | 10 | Code under [generated-sources/](./generated-sources) is generated by a set of scripts under [build-scripts/](./build-scripts). These are written for Node and require it to be installed. 11 | 12 | To regenerate sources: 13 | 14 | ```sh 15 | cd build-scripts 16 | npm ci # install dependencies 17 | npm run build 18 | ``` 19 | 20 | ## Contributing 21 | 22 | * Open a Github issue with a description of your desired change. If one exists already, leave a message stating that you are working on it with the date you expect it to be complete. 23 | * Fork this repo, and clone the forked repo. 24 | * Install dependencies with `mvn`. 25 | * Build and test in your environment with `mvn compile test`. 26 | * Create a feature branch. Make your changes. Add tests. 27 | * Build and test in your environment with `mvn compile test`. 28 | * Make a commit that includes the text "fixes #*XX*" where *XX* is the Github issue. 29 | * Open a Pull Request on Github. 30 | 31 | ## License 32 | 33 | Copyright 2017 Shape Security, Inc. 34 | 35 | Licensed under the Apache License, Version 2.0 (the "License"); 36 | you may not use this file except in compliance with the License. 37 | You may obtain a copy of the License at 38 | 39 | http://www.apache.org/licenses/LICENSE-2.0 40 | 41 | Unless required by applicable law or agreed to in writing, software 42 | distributed under the License is distributed on an "AS IS" BASIS, 43 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 44 | See the License for the specific language governing permissions and 45 | limitations under the License. 46 | -------------------------------------------------------------------------------- /build-scripts/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "scripts": { 4 | "build": "for i in scripts/build/*; do node $i; done", 5 | "clean": "rm -rf ../generated-sources", 6 | "lint": "eslint ." 7 | }, 8 | "dependencies": { 9 | "shift-spec-idl": "2018.0.1", 10 | "shift-spec": "2018.0.2", 11 | "eslint": "^5.8.0", 12 | "shift-spec-consumer": "^1.0.1" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /build-scripts/scripts/lib/out-dir.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | let path = require('path'); 4 | 5 | module.exports = { 6 | outDir: path.join(__dirname, '../../../generated-sources/main/java/com/shapesecurity/shift/es2018') + '/', 7 | }; 8 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright 2014 Shape Security, Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | mvn compile test package $* -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/AssignmentTarget.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | public interface AssignmentTarget extends AssignmentTargetAssignmentTargetWithDefault, VariableDeclarationAssignmentTarget {} 22 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/AssignmentTargetAssignmentTargetWithDefault.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | public interface AssignmentTargetAssignmentTargetWithDefault extends Node {} 22 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/AssignmentTargetIdentifier.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | 24 | public class AssignmentTargetIdentifier extends VariableReference implements SimpleAssignmentTarget { 25 | 26 | 27 | public AssignmentTargetIdentifier (@Nonnull String name) { 28 | super(name); 29 | } 30 | 31 | 32 | @Override 33 | public boolean equals(Object object) { 34 | return object instanceof AssignmentTargetIdentifier && this.name.equals(((AssignmentTargetIdentifier) object).name); 35 | } 36 | 37 | 38 | @Override 39 | public int hashCode() { 40 | int code = HashCodeBuilder.put(0, "AssignmentTargetIdentifier"); 41 | code = HashCodeBuilder.put(code, this.name); 42 | return code; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/AssignmentTargetPattern.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | public interface AssignmentTargetPattern extends AssignmentTarget {} 22 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/AssignmentTargetProperty.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | public interface AssignmentTargetProperty extends Node {} 22 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/AwaitExpression.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | import com.shapesecurity.shift.es2018.ast.operators.Precedence; 24 | 25 | public class AwaitExpression implements Expression { 26 | @Nonnull 27 | public final Expression expression; 28 | 29 | 30 | public AwaitExpression (@Nonnull Expression expression) { 31 | this.expression = expression; 32 | } 33 | 34 | 35 | @Override 36 | public boolean equals(Object object) { 37 | return object instanceof AwaitExpression && this.expression.equals(((AwaitExpression) object).expression); 38 | } 39 | 40 | 41 | @Override 42 | public int hashCode() { 43 | int code = HashCodeBuilder.put(0, "AwaitExpression"); 44 | code = HashCodeBuilder.put(code, this.expression); 45 | return code; 46 | } 47 | 48 | @Override 49 | @Nonnull 50 | public Precedence getPrecedence() { 51 | return Precedence.PREFIX; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/Binding.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | public interface Binding extends Parameter, BindingBindingWithDefault {} 22 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/BindingBindingWithDefault.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | public interface BindingBindingWithDefault extends Node {} 22 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/BindingIdentifier.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | 24 | public class BindingIdentifier extends VariableReference implements Binding { 25 | 26 | 27 | public BindingIdentifier (@Nonnull String name) { 28 | super(name); 29 | } 30 | 31 | 32 | @Override 33 | public boolean equals(Object object) { 34 | return object instanceof BindingIdentifier && this.name.equals(((BindingIdentifier) object).name); 35 | } 36 | 37 | 38 | @Override 39 | public int hashCode() { 40 | int code = HashCodeBuilder.put(0, "BindingIdentifier"); 41 | code = HashCodeBuilder.put(code, this.name); 42 | return code; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/BindingPattern.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | public interface BindingPattern extends Binding {} 22 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/BindingProperty.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | public interface BindingProperty extends Node {} 22 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/BindingWithDefault.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | 24 | public class BindingWithDefault implements Node, Parameter, BindingBindingWithDefault { 25 | @Nonnull 26 | public final Binding binding; 27 | 28 | @Nonnull 29 | public final Expression init; 30 | 31 | 32 | public BindingWithDefault (@Nonnull Binding binding, @Nonnull Expression init) { 33 | this.binding = binding; 34 | this.init = init; 35 | } 36 | 37 | 38 | @Override 39 | public boolean equals(Object object) { 40 | return object instanceof BindingWithDefault && this.binding.equals(((BindingWithDefault) object).binding) && this.init.equals(((BindingWithDefault) object).init); 41 | } 42 | 43 | 44 | @Override 45 | public int hashCode() { 46 | int code = HashCodeBuilder.put(0, "BindingWithDefault"); 47 | code = HashCodeBuilder.put(code, this.binding); 48 | code = HashCodeBuilder.put(code, this.init); 49 | return code; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/Block.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | import com.shapesecurity.functional.data.ImmutableList; 24 | 25 | public class Block implements Node { 26 | @Nonnull 27 | public final ImmutableList statements; 28 | 29 | 30 | public Block (@Nonnull ImmutableList statements) { 31 | this.statements = statements; 32 | } 33 | 34 | 35 | @Override 36 | public boolean equals(Object object) { 37 | return object instanceof Block && this.statements.equals(((Block) object).statements); 38 | } 39 | 40 | 41 | @Override 42 | public int hashCode() { 43 | int code = HashCodeBuilder.put(0, "Block"); 44 | code = HashCodeBuilder.put(code, this.statements); 45 | return code; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/BlockStatement.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | 24 | public class BlockStatement implements Statement { 25 | @Nonnull 26 | public final Block block; 27 | 28 | 29 | public BlockStatement (@Nonnull Block block) { 30 | this.block = block; 31 | } 32 | 33 | 34 | @Override 35 | public boolean equals(Object object) { 36 | return object instanceof BlockStatement && this.block.equals(((BlockStatement) object).block); 37 | } 38 | 39 | 40 | @Override 41 | public int hashCode() { 42 | int code = HashCodeBuilder.put(0, "BlockStatement"); 43 | code = HashCodeBuilder.put(code, this.block); 44 | return code; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/BreakStatement.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | import com.shapesecurity.functional.data.Maybe; 24 | 25 | public class BreakStatement implements Statement { 26 | @Nonnull 27 | public final Maybe label; 28 | 29 | 30 | public BreakStatement (@Nonnull Maybe label) { 31 | this.label = label; 32 | } 33 | 34 | 35 | @Override 36 | public boolean equals(Object object) { 37 | return object instanceof BreakStatement && this.label.equals(((BreakStatement) object).label); 38 | } 39 | 40 | 41 | @Override 42 | public int hashCode() { 43 | int code = HashCodeBuilder.put(0, "BreakStatement"); 44 | code = HashCodeBuilder.put(code, this.label); 45 | return code; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/CatchClause.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | 24 | public class CatchClause implements Node { 25 | @Nonnull 26 | public final Binding binding; 27 | 28 | @Nonnull 29 | public final Block body; 30 | 31 | 32 | public CatchClause (@Nonnull Binding binding, @Nonnull Block body) { 33 | this.binding = binding; 34 | this.body = body; 35 | } 36 | 37 | 38 | @Override 39 | public boolean equals(Object object) { 40 | return object instanceof CatchClause && this.binding.equals(((CatchClause) object).binding) && this.body.equals(((CatchClause) object).body); 41 | } 42 | 43 | 44 | @Override 45 | public int hashCode() { 46 | int code = HashCodeBuilder.put(0, "CatchClause"); 47 | code = HashCodeBuilder.put(code, this.binding); 48 | code = HashCodeBuilder.put(code, this.body); 49 | return code; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/ClassElement.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | 24 | public class ClassElement implements Node { 25 | @Nonnull 26 | public final boolean isStatic; 27 | 28 | @Nonnull 29 | public final MethodDefinition method; 30 | 31 | 32 | public ClassElement (boolean isStatic, @Nonnull MethodDefinition method) { 33 | this.isStatic = isStatic; 34 | this.method = method; 35 | } 36 | 37 | 38 | @Override 39 | public boolean equals(Object object) { 40 | return object instanceof ClassElement && this.isStatic == ((ClassElement) object).isStatic && this.method.equals(((ClassElement) object).method); 41 | } 42 | 43 | 44 | @Override 45 | public int hashCode() { 46 | int code = HashCodeBuilder.put(0, "ClassElement"); 47 | code = HashCodeBuilder.put(code, this.isStatic); 48 | code = HashCodeBuilder.put(code, this.method); 49 | return code; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/ComputedMemberExpression.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | 24 | public class ComputedMemberExpression extends MemberExpression { 25 | @Nonnull 26 | public final Expression expression; 27 | 28 | 29 | public ComputedMemberExpression (@Nonnull ExpressionSuper object, @Nonnull Expression expression) { 30 | super(object); 31 | this.expression = expression; 32 | } 33 | 34 | 35 | @Override 36 | public boolean equals(Object object) { 37 | return object instanceof ComputedMemberExpression && this.object.equals(((ComputedMemberExpression) object).object) && this.expression.equals(((ComputedMemberExpression) object).expression); 38 | } 39 | 40 | 41 | @Override 42 | public int hashCode() { 43 | int code = HashCodeBuilder.put(0, "ComputedMemberExpression"); 44 | code = HashCodeBuilder.put(code, this.object); 45 | code = HashCodeBuilder.put(code, this.expression); 46 | return code; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/ComputedPropertyName.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | 24 | public class ComputedPropertyName implements PropertyName { 25 | @Nonnull 26 | public final Expression expression; 27 | 28 | 29 | public ComputedPropertyName (@Nonnull Expression expression) { 30 | this.expression = expression; 31 | } 32 | 33 | 34 | @Override 35 | public boolean equals(Object object) { 36 | return object instanceof ComputedPropertyName && this.expression.equals(((ComputedPropertyName) object).expression); 37 | } 38 | 39 | 40 | @Override 41 | public int hashCode() { 42 | int code = HashCodeBuilder.put(0, "ComputedPropertyName"); 43 | code = HashCodeBuilder.put(code, this.expression); 44 | return code; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/ContinueStatement.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | import com.shapesecurity.functional.data.Maybe; 24 | 25 | public class ContinueStatement implements Statement { 26 | @Nonnull 27 | public final Maybe label; 28 | 29 | 30 | public ContinueStatement (@Nonnull Maybe label) { 31 | this.label = label; 32 | } 33 | 34 | 35 | @Override 36 | public boolean equals(Object object) { 37 | return object instanceof ContinueStatement && this.label.equals(((ContinueStatement) object).label); 38 | } 39 | 40 | 41 | @Override 42 | public int hashCode() { 43 | int code = HashCodeBuilder.put(0, "ContinueStatement"); 44 | code = HashCodeBuilder.put(code, this.label); 45 | return code; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/DataProperty.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | 24 | public class DataProperty extends NamedObjectProperty { 25 | @Nonnull 26 | public final Expression expression; 27 | 28 | 29 | public DataProperty (@Nonnull PropertyName name, @Nonnull Expression expression) { 30 | super(name); 31 | this.expression = expression; 32 | } 33 | 34 | 35 | @Override 36 | public boolean equals(Object object) { 37 | return object instanceof DataProperty && this.name.equals(((DataProperty) object).name) && this.expression.equals(((DataProperty) object).expression); 38 | } 39 | 40 | 41 | @Override 42 | public int hashCode() { 43 | int code = HashCodeBuilder.put(0, "DataProperty"); 44 | code = HashCodeBuilder.put(code, this.name); 45 | code = HashCodeBuilder.put(code, this.expression); 46 | return code; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/DebuggerStatement.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | 24 | public class DebuggerStatement implements Statement { 25 | 26 | 27 | public DebuggerStatement () {} 28 | 29 | 30 | @Override 31 | public boolean equals(Object object) { 32 | return object instanceof DebuggerStatement; 33 | } 34 | 35 | 36 | @Override 37 | public int hashCode() { 38 | int code = HashCodeBuilder.put(0, "DebuggerStatement"); 39 | return code; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/Directive.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | 24 | public class Directive implements Node { 25 | @Nonnull 26 | public final String rawValue; 27 | 28 | 29 | public Directive (@Nonnull String rawValue) { 30 | this.rawValue = rawValue; 31 | } 32 | 33 | 34 | @Override 35 | public boolean equals(Object object) { 36 | return object instanceof Directive && this.rawValue.equals(((Directive) object).rawValue); 37 | } 38 | 39 | 40 | @Override 41 | public int hashCode() { 42 | int code = HashCodeBuilder.put(0, "Directive"); 43 | code = HashCodeBuilder.put(code, this.rawValue); 44 | return code; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/DoWhileStatement.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | 24 | public class DoWhileStatement extends IterationStatement { 25 | @Nonnull 26 | public final Expression test; 27 | 28 | 29 | public DoWhileStatement (@Nonnull Statement body, @Nonnull Expression test) { 30 | super(body); 31 | this.test = test; 32 | } 33 | 34 | 35 | @Override 36 | public boolean equals(Object object) { 37 | return object instanceof DoWhileStatement && this.body.equals(((DoWhileStatement) object).body) && this.test.equals(((DoWhileStatement) object).test); 38 | } 39 | 40 | 41 | @Override 42 | public int hashCode() { 43 | int code = HashCodeBuilder.put(0, "DoWhileStatement"); 44 | code = HashCodeBuilder.put(code, this.body); 45 | code = HashCodeBuilder.put(code, this.test); 46 | return code; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/EmptyStatement.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | 24 | public class EmptyStatement implements Statement { 25 | 26 | 27 | public EmptyStatement () {} 28 | 29 | 30 | @Override 31 | public boolean equals(Object object) { 32 | return object instanceof EmptyStatement; 33 | } 34 | 35 | 36 | @Override 37 | public int hashCode() { 38 | int code = HashCodeBuilder.put(0, "EmptyStatement"); 39 | return code; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/Export.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | 24 | public class Export implements ExportDeclaration { 25 | @Nonnull 26 | public final FunctionDeclarationClassDeclarationVariableDeclaration declaration; 27 | 28 | 29 | public Export (@Nonnull FunctionDeclarationClassDeclarationVariableDeclaration declaration) { 30 | this.declaration = declaration; 31 | } 32 | 33 | 34 | @Override 35 | public boolean equals(Object object) { 36 | return object instanceof Export && this.declaration.equals(((Export) object).declaration); 37 | } 38 | 39 | 40 | @Override 41 | public int hashCode() { 42 | int code = HashCodeBuilder.put(0, "Export"); 43 | code = HashCodeBuilder.put(code, this.declaration); 44 | return code; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/ExportAllFrom.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | 24 | public class ExportAllFrom implements ExportDeclaration { 25 | @Nonnull 26 | public final String moduleSpecifier; 27 | 28 | 29 | public ExportAllFrom (@Nonnull String moduleSpecifier) { 30 | this.moduleSpecifier = moduleSpecifier; 31 | } 32 | 33 | 34 | @Override 35 | public boolean equals(Object object) { 36 | return object instanceof ExportAllFrom && this.moduleSpecifier.equals(((ExportAllFrom) object).moduleSpecifier); 37 | } 38 | 39 | 40 | @Override 41 | public int hashCode() { 42 | int code = HashCodeBuilder.put(0, "ExportAllFrom"); 43 | code = HashCodeBuilder.put(code, this.moduleSpecifier); 44 | return code; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/ExportDeclaration.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | public interface ExportDeclaration extends Node, ImportDeclarationExportDeclarationStatement {} 22 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/ExportDefault.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | 24 | public class ExportDefault implements ExportDeclaration { 25 | @Nonnull 26 | public final FunctionDeclarationClassDeclarationExpression body; 27 | 28 | 29 | public ExportDefault (@Nonnull FunctionDeclarationClassDeclarationExpression body) { 30 | this.body = body; 31 | } 32 | 33 | 34 | @Override 35 | public boolean equals(Object object) { 36 | return object instanceof ExportDefault && this.body.equals(((ExportDefault) object).body); 37 | } 38 | 39 | 40 | @Override 41 | public int hashCode() { 42 | int code = HashCodeBuilder.put(0, "ExportDefault"); 43 | code = HashCodeBuilder.put(code, this.body); 44 | return code; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/ExportLocals.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | import com.shapesecurity.functional.data.ImmutableList; 24 | 25 | public class ExportLocals implements ExportDeclaration { 26 | @Nonnull 27 | public final ImmutableList namedExports; 28 | 29 | 30 | public ExportLocals (@Nonnull ImmutableList namedExports) { 31 | this.namedExports = namedExports; 32 | } 33 | 34 | 35 | @Override 36 | public boolean equals(Object object) { 37 | return object instanceof ExportLocals && this.namedExports.equals(((ExportLocals) object).namedExports); 38 | } 39 | 40 | 41 | @Override 42 | public int hashCode() { 43 | int code = HashCodeBuilder.put(0, "ExportLocals"); 44 | code = HashCodeBuilder.put(code, this.namedExports); 45 | return code; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/Expression.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.shift.es2018.ast.operators.Precedence; 23 | 24 | public interface Expression extends Node, ExpressionSuper, FunctionDeclarationClassDeclarationExpression, SpreadElementExpression, FunctionBodyExpression, ExpressionTemplateElement, VariableDeclarationExpression { 25 | @Nonnull 26 | public Precedence getPrecedence(); 27 | } 28 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/ExpressionStatement.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | 24 | public class ExpressionStatement implements Statement { 25 | @Nonnull 26 | public final Expression expression; 27 | 28 | 29 | public ExpressionStatement (@Nonnull Expression expression) { 30 | this.expression = expression; 31 | } 32 | 33 | 34 | @Override 35 | public boolean equals(Object object) { 36 | return object instanceof ExpressionStatement && this.expression.equals(((ExpressionStatement) object).expression); 37 | } 38 | 39 | 40 | @Override 41 | public int hashCode() { 42 | int code = HashCodeBuilder.put(0, "ExpressionStatement"); 43 | code = HashCodeBuilder.put(code, this.expression); 44 | return code; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/ExpressionSuper.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | public interface ExpressionSuper extends Node {} 22 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/ExpressionTemplateElement.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | public interface ExpressionTemplateElement extends Node {} 22 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/FunctionBodyExpression.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | public interface FunctionBodyExpression extends Node {} 22 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/FunctionDeclarationClassDeclarationExpression.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | public interface FunctionDeclarationClassDeclarationExpression extends Node {} 22 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/FunctionDeclarationClassDeclarationVariableDeclaration.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | public interface FunctionDeclarationClassDeclarationVariableDeclaration extends Node {} 22 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/Getter.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | 24 | public class Getter extends MethodDefinition { 25 | 26 | 27 | public Getter (@Nonnull PropertyName name, @Nonnull FunctionBody body) { 28 | super(name, body); 29 | } 30 | 31 | 32 | @Override 33 | public boolean equals(Object object) { 34 | return object instanceof Getter && this.name.equals(((Getter) object).name) && this.body.equals(((Getter) object).body); 35 | } 36 | 37 | 38 | @Override 39 | public int hashCode() { 40 | int code = HashCodeBuilder.put(0, "Getter"); 41 | code = HashCodeBuilder.put(code, this.name); 42 | code = HashCodeBuilder.put(code, this.body); 43 | return code; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/IdentifierExpression.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | import com.shapesecurity.shift.es2018.ast.operators.Precedence; 24 | 25 | public class IdentifierExpression extends VariableReference implements Expression { 26 | 27 | 28 | public IdentifierExpression (@Nonnull String name) { 29 | super(name); 30 | } 31 | 32 | 33 | @Override 34 | public boolean equals(Object object) { 35 | return object instanceof IdentifierExpression && this.name.equals(((IdentifierExpression) object).name); 36 | } 37 | 38 | 39 | @Override 40 | public int hashCode() { 41 | int code = HashCodeBuilder.put(0, "IdentifierExpression"); 42 | code = HashCodeBuilder.put(code, this.name); 43 | return code; 44 | } 45 | 46 | @Override 47 | @Nonnull 48 | public Precedence getPrecedence() { 49 | return Precedence.PRIMARY; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/ImportDeclaration.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | 24 | public abstract class ImportDeclaration implements Node, ImportDeclarationExportDeclarationStatement { 25 | @Nonnull 26 | public final String moduleSpecifier; 27 | 28 | 29 | public ImportDeclaration (@Nonnull String moduleSpecifier) { 30 | this.moduleSpecifier = moduleSpecifier; 31 | } 32 | 33 | 34 | @Override 35 | public boolean equals(Object object) { 36 | return object instanceof ImportDeclaration && this.moduleSpecifier.equals(((ImportDeclaration) object).moduleSpecifier); 37 | } 38 | 39 | 40 | @Override 41 | public int hashCode() { 42 | int code = HashCodeBuilder.put(0, "ImportDeclaration"); 43 | code = HashCodeBuilder.put(code, this.moduleSpecifier); 44 | return code; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/ImportDeclarationExportDeclarationStatement.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | public interface ImportDeclarationExportDeclarationStatement extends Node {} 22 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/IterationStatement.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | 24 | public abstract class IterationStatement implements Statement { 25 | @Nonnull 26 | public final Statement body; 27 | 28 | 29 | public IterationStatement (@Nonnull Statement body) { 30 | this.body = body; 31 | } 32 | 33 | 34 | @Override 35 | public boolean equals(Object object) { 36 | return object instanceof IterationStatement && this.body.equals(((IterationStatement) object).body); 37 | } 38 | 39 | 40 | @Override 41 | public int hashCode() { 42 | int code = HashCodeBuilder.put(0, "IterationStatement"); 43 | code = HashCodeBuilder.put(code, this.body); 44 | return code; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/LabeledStatement.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | 24 | public class LabeledStatement implements Statement { 25 | @Nonnull 26 | public final String label; 27 | 28 | @Nonnull 29 | public final Statement body; 30 | 31 | 32 | public LabeledStatement (@Nonnull String label, @Nonnull Statement body) { 33 | this.label = label; 34 | this.body = body; 35 | } 36 | 37 | 38 | @Override 39 | public boolean equals(Object object) { 40 | return object instanceof LabeledStatement && this.label.equals(((LabeledStatement) object).label) && this.body.equals(((LabeledStatement) object).body); 41 | } 42 | 43 | 44 | @Override 45 | public int hashCode() { 46 | int code = HashCodeBuilder.put(0, "LabeledStatement"); 47 | code = HashCodeBuilder.put(code, this.label); 48 | code = HashCodeBuilder.put(code, this.body); 49 | return code; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/LiteralBooleanExpression.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | import com.shapesecurity.shift.es2018.ast.operators.Precedence; 24 | 25 | public class LiteralBooleanExpression implements Expression { 26 | @Nonnull 27 | public final boolean value; 28 | 29 | 30 | public LiteralBooleanExpression (boolean value) { 31 | this.value = value; 32 | } 33 | 34 | 35 | @Override 36 | public boolean equals(Object object) { 37 | return object instanceof LiteralBooleanExpression && this.value == ((LiteralBooleanExpression) object).value; 38 | } 39 | 40 | 41 | @Override 42 | public int hashCode() { 43 | int code = HashCodeBuilder.put(0, "LiteralBooleanExpression"); 44 | code = HashCodeBuilder.put(code, this.value); 45 | return code; 46 | } 47 | 48 | @Override 49 | @Nonnull 50 | public Precedence getPrecedence() { 51 | return Precedence.PRIMARY; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/LiteralInfinityExpression.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | import com.shapesecurity.shift.es2018.ast.operators.Precedence; 24 | 25 | public class LiteralInfinityExpression implements Expression { 26 | 27 | 28 | public LiteralInfinityExpression () {} 29 | 30 | 31 | @Override 32 | public boolean equals(Object object) { 33 | return object instanceof LiteralInfinityExpression; 34 | } 35 | 36 | 37 | @Override 38 | public int hashCode() { 39 | int code = HashCodeBuilder.put(0, "LiteralInfinityExpression"); 40 | return code; 41 | } 42 | 43 | @Override 44 | @Nonnull 45 | public Precedence getPrecedence() { 46 | return Precedence.PRIMARY; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/LiteralNullExpression.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | import com.shapesecurity.shift.es2018.ast.operators.Precedence; 24 | 25 | public class LiteralNullExpression implements Expression { 26 | 27 | 28 | public LiteralNullExpression () {} 29 | 30 | 31 | @Override 32 | public boolean equals(Object object) { 33 | return object instanceof LiteralNullExpression; 34 | } 35 | 36 | 37 | @Override 38 | public int hashCode() { 39 | int code = HashCodeBuilder.put(0, "LiteralNullExpression"); 40 | return code; 41 | } 42 | 43 | @Override 44 | @Nonnull 45 | public Precedence getPrecedence() { 46 | return Precedence.PRIMARY; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/LiteralNumericExpression.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | import com.shapesecurity.shift.es2018.ast.operators.Precedence; 24 | 25 | public class LiteralNumericExpression implements Expression { 26 | @Nonnull 27 | public final double value; 28 | 29 | 30 | public LiteralNumericExpression (@Nonnull double value) { 31 | this.value = value; 32 | } 33 | 34 | 35 | @Override 36 | public boolean equals(Object object) { 37 | return object instanceof LiteralNumericExpression && this.value == ((LiteralNumericExpression) object).value; 38 | } 39 | 40 | 41 | @Override 42 | public int hashCode() { 43 | int code = HashCodeBuilder.put(0, "LiteralNumericExpression"); 44 | code = HashCodeBuilder.put(code, this.value); 45 | return code; 46 | } 47 | 48 | @Override 49 | @Nonnull 50 | public Precedence getPrecedence() { 51 | return Precedence.PRIMARY; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/LiteralStringExpression.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | import com.shapesecurity.shift.es2018.ast.operators.Precedence; 24 | 25 | public class LiteralStringExpression implements Expression { 26 | @Nonnull 27 | public final String value; 28 | 29 | 30 | public LiteralStringExpression (@Nonnull String value) { 31 | this.value = value; 32 | } 33 | 34 | 35 | @Override 36 | public boolean equals(Object object) { 37 | return object instanceof LiteralStringExpression && this.value.equals(((LiteralStringExpression) object).value); 38 | } 39 | 40 | 41 | @Override 42 | public int hashCode() { 43 | int code = HashCodeBuilder.put(0, "LiteralStringExpression"); 44 | code = HashCodeBuilder.put(code, this.value); 45 | return code; 46 | } 47 | 48 | @Override 49 | @Nonnull 50 | public Precedence getPrecedence() { 51 | return Precedence.PRIMARY; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/MemberAssignmentTarget.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | 24 | public abstract class MemberAssignmentTarget implements Node, SimpleAssignmentTarget { 25 | @Nonnull 26 | public final ExpressionSuper object; 27 | 28 | 29 | public MemberAssignmentTarget (@Nonnull ExpressionSuper object) { 30 | this.object = object; 31 | } 32 | 33 | 34 | @Override 35 | public boolean equals(Object object) { 36 | return object instanceof MemberAssignmentTarget && this.object.equals(((MemberAssignmentTarget) object).object); 37 | } 38 | 39 | 40 | @Override 41 | public int hashCode() { 42 | int code = HashCodeBuilder.put(0, "MemberAssignmentTarget"); 43 | code = HashCodeBuilder.put(code, this.object); 44 | return code; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/MethodDefinition.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | 24 | public abstract class MethodDefinition extends NamedObjectProperty { 25 | @Nonnull 26 | public final FunctionBody body; 27 | 28 | 29 | public MethodDefinition (@Nonnull PropertyName name, @Nonnull FunctionBody body) { 30 | super(name); 31 | this.body = body; 32 | } 33 | 34 | 35 | @Override 36 | public boolean equals(Object object) { 37 | return object instanceof MethodDefinition && this.name.equals(((MethodDefinition) object).name) && this.body.equals(((MethodDefinition) object).body); 38 | } 39 | 40 | 41 | @Override 42 | public int hashCode() { 43 | int code = HashCodeBuilder.put(0, "MethodDefinition"); 44 | code = HashCodeBuilder.put(code, this.name); 45 | code = HashCodeBuilder.put(code, this.body); 46 | return code; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/NamedObjectProperty.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | 24 | public abstract class NamedObjectProperty implements ObjectProperty { 25 | @Nonnull 26 | public final PropertyName name; 27 | 28 | 29 | public NamedObjectProperty (@Nonnull PropertyName name) { 30 | this.name = name; 31 | } 32 | 33 | 34 | @Override 35 | public boolean equals(Object object) { 36 | return object instanceof NamedObjectProperty && this.name.equals(((NamedObjectProperty) object).name); 37 | } 38 | 39 | 40 | @Override 41 | public int hashCode() { 42 | int code = HashCodeBuilder.put(0, "NamedObjectProperty"); 43 | code = HashCodeBuilder.put(code, this.name); 44 | return code; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/NewTargetExpression.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | import com.shapesecurity.shift.es2018.ast.operators.Precedence; 24 | 25 | public class NewTargetExpression implements Expression { 26 | 27 | 28 | public NewTargetExpression () {} 29 | 30 | 31 | @Override 32 | public boolean equals(Object object) { 33 | return object instanceof NewTargetExpression; 34 | } 35 | 36 | 37 | @Override 38 | public int hashCode() { 39 | int code = HashCodeBuilder.put(0, "NewTargetExpression"); 40 | return code; 41 | } 42 | 43 | @Override 44 | @Nonnull 45 | public Precedence getPrecedence() { 46 | return Precedence.MEMBER; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/Node.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | public interface Node {} 22 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/ObjectProperty.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | public interface ObjectProperty extends Node {} 22 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/Parameter.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | public interface Parameter extends Node {} 22 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/Program.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | public interface Program extends Node {} 22 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/PropertyName.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | public interface PropertyName extends Node {} 22 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/ReturnStatement.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | import com.shapesecurity.functional.data.Maybe; 24 | 25 | public class ReturnStatement implements Statement { 26 | @Nonnull 27 | public final Maybe expression; 28 | 29 | 30 | public ReturnStatement (@Nonnull Maybe expression) { 31 | this.expression = expression; 32 | } 33 | 34 | 35 | @Override 36 | public boolean equals(Object object) { 37 | return object instanceof ReturnStatement && this.expression.equals(((ReturnStatement) object).expression); 38 | } 39 | 40 | 41 | @Override 42 | public int hashCode() { 43 | int code = HashCodeBuilder.put(0, "ReturnStatement"); 44 | code = HashCodeBuilder.put(code, this.expression); 45 | return code; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/Setter.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | 24 | public class Setter extends MethodDefinition { 25 | @Nonnull 26 | public final Parameter param; 27 | 28 | 29 | public Setter (@Nonnull PropertyName name, @Nonnull Parameter param, @Nonnull FunctionBody body) { 30 | super(name, body); 31 | this.param = param; 32 | } 33 | 34 | 35 | @Override 36 | public boolean equals(Object object) { 37 | return object instanceof Setter && this.name.equals(((Setter) object).name) && this.param.equals(((Setter) object).param) && this.body.equals(((Setter) object).body); 38 | } 39 | 40 | 41 | @Override 42 | public int hashCode() { 43 | int code = HashCodeBuilder.put(0, "Setter"); 44 | code = HashCodeBuilder.put(code, this.name); 45 | code = HashCodeBuilder.put(code, this.param); 46 | code = HashCodeBuilder.put(code, this.body); 47 | return code; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/ShorthandProperty.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | 24 | public class ShorthandProperty implements ObjectProperty { 25 | @Nonnull 26 | public final IdentifierExpression name; 27 | 28 | 29 | public ShorthandProperty (@Nonnull IdentifierExpression name) { 30 | this.name = name; 31 | } 32 | 33 | 34 | @Override 35 | public boolean equals(Object object) { 36 | return object instanceof ShorthandProperty && this.name.equals(((ShorthandProperty) object).name); 37 | } 38 | 39 | 40 | @Override 41 | public int hashCode() { 42 | int code = HashCodeBuilder.put(0, "ShorthandProperty"); 43 | code = HashCodeBuilder.put(code, this.name); 44 | return code; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/SimpleAssignmentTarget.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | public interface SimpleAssignmentTarget extends AssignmentTarget {} 22 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/SpreadElement.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | 24 | public class SpreadElement implements Node, SpreadElementExpression { 25 | @Nonnull 26 | public final Expression expression; 27 | 28 | 29 | public SpreadElement (@Nonnull Expression expression) { 30 | this.expression = expression; 31 | } 32 | 33 | 34 | @Override 35 | public boolean equals(Object object) { 36 | return object instanceof SpreadElement && this.expression.equals(((SpreadElement) object).expression); 37 | } 38 | 39 | 40 | @Override 41 | public int hashCode() { 42 | int code = HashCodeBuilder.put(0, "SpreadElement"); 43 | code = HashCodeBuilder.put(code, this.expression); 44 | return code; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/SpreadElementExpression.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | public interface SpreadElementExpression extends Node {} 22 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/SpreadProperty.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | 24 | public class SpreadProperty implements ObjectProperty { 25 | @Nonnull 26 | public final Expression expression; 27 | 28 | 29 | public SpreadProperty (@Nonnull Expression expression) { 30 | this.expression = expression; 31 | } 32 | 33 | 34 | @Override 35 | public boolean equals(Object object) { 36 | return object instanceof SpreadProperty && this.expression.equals(((SpreadProperty) object).expression); 37 | } 38 | 39 | 40 | @Override 41 | public int hashCode() { 42 | int code = HashCodeBuilder.put(0, "SpreadProperty"); 43 | code = HashCodeBuilder.put(code, this.expression); 44 | return code; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/Statement.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | public interface Statement extends Node, ImportDeclarationExportDeclarationStatement {} 22 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/StaticMemberExpression.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | 24 | public class StaticMemberExpression extends MemberExpression { 25 | @Nonnull 26 | public final String property; 27 | 28 | 29 | public StaticMemberExpression (@Nonnull ExpressionSuper object, @Nonnull String property) { 30 | super(object); 31 | this.property = property; 32 | } 33 | 34 | 35 | @Override 36 | public boolean equals(Object object) { 37 | return object instanceof StaticMemberExpression && this.object.equals(((StaticMemberExpression) object).object) && this.property.equals(((StaticMemberExpression) object).property); 38 | } 39 | 40 | 41 | @Override 42 | public int hashCode() { 43 | int code = HashCodeBuilder.put(0, "StaticMemberExpression"); 44 | code = HashCodeBuilder.put(code, this.object); 45 | code = HashCodeBuilder.put(code, this.property); 46 | return code; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/StaticPropertyName.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | 24 | public class StaticPropertyName implements PropertyName { 25 | @Nonnull 26 | public final String value; 27 | 28 | 29 | public StaticPropertyName (@Nonnull String value) { 30 | this.value = value; 31 | } 32 | 33 | 34 | @Override 35 | public boolean equals(Object object) { 36 | return object instanceof StaticPropertyName && this.value.equals(((StaticPropertyName) object).value); 37 | } 38 | 39 | 40 | @Override 41 | public int hashCode() { 42 | int code = HashCodeBuilder.put(0, "StaticPropertyName"); 43 | code = HashCodeBuilder.put(code, this.value); 44 | return code; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/Super.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | 24 | public class Super implements Node, ExpressionSuper { 25 | 26 | 27 | public Super () {} 28 | 29 | 30 | @Override 31 | public boolean equals(Object object) { 32 | return object instanceof Super; 33 | } 34 | 35 | 36 | @Override 37 | public int hashCode() { 38 | int code = HashCodeBuilder.put(0, "Super"); 39 | return code; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/SwitchDefault.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | import com.shapesecurity.functional.data.ImmutableList; 24 | 25 | public class SwitchDefault implements Node { 26 | @Nonnull 27 | public final ImmutableList consequent; 28 | 29 | 30 | public SwitchDefault (@Nonnull ImmutableList consequent) { 31 | this.consequent = consequent; 32 | } 33 | 34 | 35 | @Override 36 | public boolean equals(Object object) { 37 | return object instanceof SwitchDefault && this.consequent.equals(((SwitchDefault) object).consequent); 38 | } 39 | 40 | 41 | @Override 42 | public int hashCode() { 43 | int code = HashCodeBuilder.put(0, "SwitchDefault"); 44 | code = HashCodeBuilder.put(code, this.consequent); 45 | return code; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/TemplateElement.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | 24 | public class TemplateElement implements Node, ExpressionTemplateElement { 25 | @Nonnull 26 | public final String rawValue; 27 | 28 | 29 | public TemplateElement (@Nonnull String rawValue) { 30 | this.rawValue = rawValue; 31 | } 32 | 33 | 34 | @Override 35 | public boolean equals(Object object) { 36 | return object instanceof TemplateElement && this.rawValue.equals(((TemplateElement) object).rawValue); 37 | } 38 | 39 | 40 | @Override 41 | public int hashCode() { 42 | int code = HashCodeBuilder.put(0, "TemplateElement"); 43 | code = HashCodeBuilder.put(code, this.rawValue); 44 | return code; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/ThisExpression.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | import com.shapesecurity.shift.es2018.ast.operators.Precedence; 24 | 25 | public class ThisExpression implements Expression { 26 | 27 | 28 | public ThisExpression () {} 29 | 30 | 31 | @Override 32 | public boolean equals(Object object) { 33 | return object instanceof ThisExpression; 34 | } 35 | 36 | 37 | @Override 38 | public int hashCode() { 39 | int code = HashCodeBuilder.put(0, "ThisExpression"); 40 | return code; 41 | } 42 | 43 | @Override 44 | @Nonnull 45 | public Precedence getPrecedence() { 46 | return Precedence.PRIMARY; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/ThrowStatement.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | 24 | public class ThrowStatement implements Statement { 25 | @Nonnull 26 | public final Expression expression; 27 | 28 | 29 | public ThrowStatement (@Nonnull Expression expression) { 30 | this.expression = expression; 31 | } 32 | 33 | 34 | @Override 35 | public boolean equals(Object object) { 36 | return object instanceof ThrowStatement && this.expression.equals(((ThrowStatement) object).expression); 37 | } 38 | 39 | 40 | @Override 41 | public int hashCode() { 42 | int code = HashCodeBuilder.put(0, "ThrowStatement"); 43 | code = HashCodeBuilder.put(code, this.expression); 44 | return code; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/TryCatchStatement.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | 24 | public class TryCatchStatement implements Statement { 25 | @Nonnull 26 | public final Block body; 27 | 28 | @Nonnull 29 | public final CatchClause catchClause; 30 | 31 | 32 | public TryCatchStatement (@Nonnull Block body, @Nonnull CatchClause catchClause) { 33 | this.body = body; 34 | this.catchClause = catchClause; 35 | } 36 | 37 | 38 | @Override 39 | public boolean equals(Object object) { 40 | return object instanceof TryCatchStatement && this.body.equals(((TryCatchStatement) object).body) && this.catchClause.equals(((TryCatchStatement) object).catchClause); 41 | } 42 | 43 | 44 | @Override 45 | public int hashCode() { 46 | int code = HashCodeBuilder.put(0, "TryCatchStatement"); 47 | code = HashCodeBuilder.put(code, this.body); 48 | code = HashCodeBuilder.put(code, this.catchClause); 49 | return code; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/VariableDeclarationAssignmentTarget.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | public interface VariableDeclarationAssignmentTarget extends Node {} 22 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/VariableDeclarationExpression.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | public interface VariableDeclarationExpression extends Node {} 22 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/VariableDeclarationStatement.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | 24 | public class VariableDeclarationStatement implements Statement { 25 | @Nonnull 26 | public final VariableDeclaration declaration; 27 | 28 | 29 | public VariableDeclarationStatement (@Nonnull VariableDeclaration declaration) { 30 | this.declaration = declaration; 31 | } 32 | 33 | 34 | @Override 35 | public boolean equals(Object object) { 36 | return object instanceof VariableDeclarationStatement && this.declaration.equals(((VariableDeclarationStatement) object).declaration); 37 | } 38 | 39 | 40 | @Override 41 | public int hashCode() { 42 | int code = HashCodeBuilder.put(0, "VariableDeclarationStatement"); 43 | code = HashCodeBuilder.put(code, this.declaration); 44 | return code; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/VariableReference.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | 24 | public abstract class VariableReference implements Node { 25 | @Nonnull 26 | public final String name; 27 | 28 | 29 | public VariableReference (@Nonnull String name) { 30 | this.name = name; 31 | } 32 | 33 | 34 | @Override 35 | public boolean equals(Object object) { 36 | return object instanceof VariableReference && this.name.equals(((VariableReference) object).name); 37 | } 38 | 39 | 40 | @Override 41 | public int hashCode() { 42 | int code = HashCodeBuilder.put(0, "VariableReference"); 43 | code = HashCodeBuilder.put(code, this.name); 44 | return code; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/WhileStatement.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | 24 | public class WhileStatement extends IterationStatement { 25 | @Nonnull 26 | public final Expression test; 27 | 28 | 29 | public WhileStatement (@Nonnull Expression test, @Nonnull Statement body) { 30 | super(body); 31 | this.test = test; 32 | } 33 | 34 | 35 | @Override 36 | public boolean equals(Object object) { 37 | return object instanceof WhileStatement && this.test.equals(((WhileStatement) object).test) && this.body.equals(((WhileStatement) object).body); 38 | } 39 | 40 | 41 | @Override 42 | public int hashCode() { 43 | int code = HashCodeBuilder.put(0, "WhileStatement"); 44 | code = HashCodeBuilder.put(code, this.test); 45 | code = HashCodeBuilder.put(code, this.body); 46 | return code; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /generated-sources/main/java/com/shapesecurity/shift/es2018/ast/WithStatement.java: -------------------------------------------------------------------------------- 1 | // Generated by ast.js 2 | /** 3 | * Copyright 2018 Shape Security, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | package com.shapesecurity.shift.es2018.ast; 20 | 21 | import javax.annotation.Nonnull; 22 | import com.shapesecurity.functional.data.HashCodeBuilder; 23 | 24 | public class WithStatement implements Statement { 25 | @Nonnull 26 | public final Expression object; 27 | 28 | @Nonnull 29 | public final Statement body; 30 | 31 | 32 | public WithStatement (@Nonnull Expression object, @Nonnull Statement body) { 33 | this.object = object; 34 | this.body = body; 35 | } 36 | 37 | 38 | @Override 39 | public boolean equals(Object object) { 40 | return object instanceof WithStatement && this.object.equals(((WithStatement) object).object) && this.body.equals(((WithStatement) object).body); 41 | } 42 | 43 | 44 | @Override 45 | public int hashCode() { 46 | int code = HashCodeBuilder.put(0, "WithStatement"); 47 | code = HashCodeBuilder.put(code, this.object); 48 | code = HashCodeBuilder.put(code, this.body); 49 | return code; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /scripts/make-unicode-regexen.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const ID_Start = require('unicode-9.0.0/Binary_Property/ID_Start/code-points.js'); 4 | const ID_Continue = require('unicode-9.0.0/Binary_Property/ID_Continue/code-points.js'); 5 | const Space_Separator = require('unicode-9.0.0/General_Category/Space_Separator/code-points.js'); 6 | 7 | 8 | function asFourHexDigits(cp) { 9 | return cp.toString(16).padStart(4, '0'); 10 | } 11 | 12 | function escape(cp) { 13 | if (cp < 0xFFFF) { 14 | return '\\u' + asFourHexDigits(cp); 15 | } 16 | const cu1 = Math.floor((cp - 0x10000) / 0x400) + 0xD800; 17 | const cu2 = (cp - 0x10000) % 0x400 + 0xDC00; 18 | return '\\u' + asFourHexDigits(cu1) + '\\u' + asFourHexDigits(cu2); 19 | } 20 | 21 | function toRegex(array) { 22 | const sorted = [...new Set(array)].sort((a, b) => a - b); 23 | const classes = []; 24 | for (let i = 0; i < sorted.length; ++i) { 25 | const cp = sorted[i]; 26 | if (cp < 128) continue; // exclude ascii 27 | if (i + 2 < sorted.length && sorted[i + 1] === cp + 1 && sorted[i + 2] === cp + 2) { 28 | // i.e. we have a range 29 | i += 2; 30 | let offset = 2; 31 | while (i + 1 < sorted.length && sorted[i + 1] === cp + offset + 1) { 32 | ++i; 33 | ++offset; 34 | } 35 | classes.push(escape(cp) + '-' + escape(sorted[i])); 36 | } else { 37 | classes.push(escape(cp)); 38 | } 39 | } 40 | return '[' + classes.join('') + ']'; 41 | } 42 | 43 | 44 | console.log('IdentifierStart:\n' + toRegex(ID_Start)); 45 | console.log('IdentifierContinue:\n' + toRegex([].concat(ID_Continue, [0x200c, 0x200d]))); 46 | console.log('Whitespace:\n' + toRegex([].concat(Space_Separator, [0x00a0, 0xfeff]))); 47 | -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/ast/VariableDeclarationKind.java: -------------------------------------------------------------------------------- 1 | package com.shapesecurity.shift.es2018.ast; 2 | 3 | public enum VariableDeclarationKind { 4 | Var("var"), 5 | Const("const"), 6 | Let("let"); 7 | public final String name; 8 | 9 | private VariableDeclarationKind(String name) { 10 | this.name = name; 11 | } 12 | 13 | @Override 14 | public String toString() { 15 | return this.name; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/ast/operators/CompoundAssignmentOperator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Shape Security, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.shapesecurity.shift.es2018.ast.operators; 18 | 19 | import javax.annotation.Nonnull; 20 | 21 | public enum CompoundAssignmentOperator implements Operator { 22 | AssignPlus("+="), 23 | AssignMinus("-="), 24 | AssignMul("*="), 25 | AssignDiv("/="), 26 | AssignRem("%="), 27 | AssignExp("**="), 28 | AssignLeftShift("<<="), 29 | AssignRightShift(">>="), 30 | AssignUnsignedRightShift(">>>="), 31 | AssignBitOr("|="), 32 | AssignBitXor("^="), 33 | AssignBitAnd("&="); 34 | 35 | @Nonnull 36 | private final String name; 37 | 38 | private CompoundAssignmentOperator(@Nonnull String name) { 39 | this.name = name; 40 | } 41 | 42 | @Nonnull 43 | public static Precedence getPrecedence() { 44 | return Precedence.ASSIGNMENT; 45 | } 46 | 47 | @Override 48 | @Nonnull 49 | public String getName() { 50 | return this.name; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/ast/operators/Operator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Shape Security, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.shapesecurity.shift.es2018.ast.operators; 18 | 19 | import javax.annotation.Nonnull; 20 | 21 | interface Operator { 22 | @Nonnull 23 | String getName(); 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/ast/operators/Precedence.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Shape Security, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.shapesecurity.shift.es2018.ast.operators; 18 | 19 | public enum Precedence { 20 | SEQUENCE, 21 | ASSIGNMENT, 22 | CONDITIONAL, 23 | LOGICAL_OR, 24 | LOGICAL_AND, 25 | BITWISE_OR, 26 | BITWISE_XOR, 27 | BITWISE_AND, 28 | EQUALITY, 29 | RELATIONAL, 30 | SHIFT, 31 | ADDITIVE, 32 | MULTIPLICATIVE, 33 | EXPONENTIAL, 34 | PREFIX, 35 | POSTFIX, 36 | NEW, 37 | CALL, 38 | MEMBER, 39 | PRIMARY 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/ast/operators/UnaryOperator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Shape Security, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.shapesecurity.shift.es2018.ast.operators; 18 | 19 | import javax.annotation.Nonnull; 20 | 21 | public enum UnaryOperator implements Operator { 22 | Plus("+"), 23 | Minus("-"), 24 | LogicalNot("!"), 25 | BitNot("~"), 26 | Typeof("typeof"), 27 | Void("void"), 28 | Delete("delete"); 29 | @Nonnull 30 | private final String name; 31 | 32 | private UnaryOperator(@Nonnull String name) { 33 | this.name = name; 34 | } 35 | 36 | @Override 37 | @Nonnull 38 | public String getName() { 39 | return this.name; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/ast/operators/UpdateOperator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Shape Security, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.shapesecurity.shift.es2018.ast.operators; 18 | 19 | import javax.annotation.Nonnull; 20 | 21 | public enum UpdateOperator implements Operator { 22 | Increment("++"), 23 | Decrement("--"); 24 | @Nonnull 25 | private final String name; 26 | 27 | private UpdateOperator(@Nonnull String name) { 28 | this.name = name; 29 | } 30 | 31 | @Override 32 | @Nonnull 33 | public String getName() { 34 | return this.name; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/codegen/FormattedCodeRepFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Shape Security, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.shapesecurity.shift.es2018.codegen; 18 | 19 | import javax.annotation.Nonnull; 20 | 21 | public class FormattedCodeRepFactory extends CodeRepFactory { 22 | @Nonnull 23 | public CodeRep semi() { 24 | return new FormattedCodeRep.Semi(); 25 | } 26 | 27 | @Nonnull 28 | @Override 29 | public CodeRep brace(@Nonnull CodeRep rep) { 30 | return new FormattedCodeRep.Brace(rep); 31 | } 32 | 33 | @Nonnull 34 | @Override 35 | public CodeRep semiOp() { 36 | return new FormattedCodeRep.SemiOp(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/codegen/PrettyCodeGen.java: -------------------------------------------------------------------------------- 1 | package com.shapesecurity.shift.es2018.codegen; 2 | 3 | import com.shapesecurity.shift.es2018.ast.Program; 4 | import javax.annotation.Nonnull; 5 | 6 | public abstract class PrettyCodeGen extends CodeGen { 7 | public PrettyCodeGen(@Nonnull CodeRepFactory factory) { 8 | super(factory); 9 | } 10 | 11 | @Nonnull 12 | public static String codeGen(@Nonnull Program program) { 13 | return codeGen(program, PRETTY); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/codegen/README.md: -------------------------------------------------------------------------------- 1 | Shift AST Code Generator 2 | ======================== 3 | 4 | ##Description 5 | 6 | The `CodeGen.codeGen` function takes a `Script` object and generates the ECMAScript string representation of it. 7 | 8 | The generated program generally parses into a `Script` object that is identical to the original one with two exceptions: 9 | * if the `Script` object cannot pass `Validator` test, the behavior of code generation is undefined. 10 | * if there is an `IfStatement` without `alternate`-clause who is directly followed by an `alternate`-clause of an 11 | `IfStatement`, the `consequent`-clause of the latter `IfStatement` is wrapped by a `BlockStatement`, resulting in a 12 | slightly different parse tree. 13 | 14 | ## Usage 15 | 16 | ```java 17 | import com.shapesecurity.shift.parser.Parser; 18 | import com.shapesecurity.shift.codegen.CodeGen; 19 | 20 | 21 | String js = "a; b;"; 22 | Script p = Parser.parse(js); 23 | String jsPrime = CodeGen.codeGen(p); 24 | ``` 25 | -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/minifier/ExpansionRule.java: -------------------------------------------------------------------------------- 1 | ///* 2 | // * Copyright 2014 Shape Security, Inc. 3 | // * 4 | // * Licensed under the Apache License, Version 2.0 (the "License"); 5 | // * you may not use this file except in compliance with the License. 6 | // * You may obtain a copy of the License at 7 | // * 8 | // * http://www.apache.org/licenses/LICENSE-2.0 9 | // * 10 | // * Unless required by applicable law or agreed to in writing, software 11 | // * distributed under the License is distributed on an "AS IS" BASIS, 12 | // * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // * See the License for the specific language governing permissions and 14 | // * limitations under the License. 15 | // */ 16 | // 17 | //package com.shapesecurity.shift.minifier; 18 | // 19 | //public class ExpansionRule extends MinificationRule { 20 | //} 21 | -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/minifier/README.md: -------------------------------------------------------------------------------- 1 | Shift AST Minifier 2 | ================== 3 | 4 | ## Description 5 | 6 | The `Minifier` class takes a `Script` object and transforms the AST so that it may be represented using the smallest 7 | source length. 8 | 9 | ## Usage 10 | 11 | ```java 12 | import com.shapesecurity.shift.minifier.Minifier; 13 | import com.shapesecurity.shift.parser.Parser; 14 | import com.shapesecurity.shift.codegen.CodeGen; 15 | 16 | // parse a javascript program 17 | String js = "a; b;"; 18 | Script p = Parser.parse(js); 19 | 20 | // specifying reduction/expansion rules for minification 21 | List reductionRules = List.list<>(FlattenBlocks.INSTANCE, ReduceNestedIfStatements.INSTANCE, ...); 22 | List expansionRules = List.list<>(); 23 | Script pPrime = Minifier.minify(p, reductionRules, expansionRules); 24 | String minified1 = CodeGen.codeGen(pPrime); 25 | 26 | // using the default sets of reduction/expansion rules 27 | Script pPrimePrime = Minifier.minify(p); 28 | String minified2 = CodeGen.codeGen(pPrimePrime); 29 | ``` 30 | -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/minifier/ReductionRule.java: -------------------------------------------------------------------------------- 1 | ///* 2 | // * Copyright 2014 Shape Security, Inc. 3 | // * 4 | // * Licensed under the Apache License, Version 2.0 (the "License"); 5 | // * you may not use this file except in compliance with the License. 6 | // * You may obtain a copy of the License at 7 | // * 8 | // * http://www.apache.org/licenses/LICENSE-2.0 9 | // * 10 | // * Unless required by applicable law or agreed to in writing, software 11 | // * distributed under the License is distributed on an "AS IS" BASIS, 12 | // * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // * See the License for the specific language governing permissions and 14 | // * limitations under the License. 15 | // */ 16 | // 17 | //package com.shapesecurity.shift.minifier; 18 | // 19 | //public class ReductionRule extends MinificationRule { 20 | //} 21 | -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/minifier/passes/expansion/ExpandBooleanLiterals.java: -------------------------------------------------------------------------------- 1 | ///* 2 | // * Copyright 2014 Shape Security, Inc. 3 | // * 4 | // * Licensed under the Apache License, Version 2.0 (the "License"); 5 | // * you may not use this file except in compliance with the License. 6 | // * You may obtain a copy of the License at 7 | // * 8 | // * http://www.apache.org/licenses/LICENSE-2.0 9 | // * 10 | // * Unless required by applicable law or agreed to in writing, software 11 | // * distributed under the License is distributed on an "AS IS" BASIS, 12 | // * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // * See the License for the specific language governing permissions and 14 | // * limitations under the License. 15 | // */ 16 | // 17 | //package com.shapesecurity.shift.minifier.passes.expansion; 18 | // 19 | //import Expression; 20 | //import com.shapesecurity.shift.ast.expression.LiteralBooleanExpression; 21 | //import com.shapesecurity.shift.ast.expression.LiteralNumericExpression; 22 | //import com.shapesecurity.shift.ast.expression.PrefixExpression; 23 | //import com.shapesecurity.shift.ast.operators.PrefixOperator; 24 | //import com.shapesecurity.shift.minifier.ExpansionRule; 25 | //import com.shapesecurity.shift.visitor.DirtyState; 26 | // 27 | //import javax.annotation.Nonnull; 28 | // 29 | //public class ExpandBooleanLiterals extends ExpansionRule { 30 | // /* expand true to !0 and false to !1 */ 31 | // public static final ExpandBooleanLiterals INSTANCE = new ExpandBooleanLiterals(); 32 | // 33 | // @Nonnull 34 | // @Override 35 | // public DirtyState transform(@Nonnull LiteralBooleanExpression node) { 36 | // return DirtyState.dirty(new PrefixExpression(PrefixOperator.LogicalNot, new LiteralNumericExpression( 37 | // node.value ? 0 : 1))); 38 | // } 39 | //} 40 | -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/minifier/passes/reduction/RemoveEmptyBlocks.java: -------------------------------------------------------------------------------- 1 | ///* 2 | // * Copyright 2014 Shape Security, Inc. 3 | // * 4 | // * Licensed under the Apache License, Version 2.0 (the "License"); 5 | // * you may not use this file except in compliance with the License. 6 | // * You may obtain a copy of the License at 7 | // * 8 | // * http://www.apache.org/licenses/LICENSE-2.0 9 | // * 10 | // * Unless required by applicable law or agreed to in writing, software 11 | // * distributed under the License is distributed on an "AS IS" BASIS, 12 | // * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // * See the License for the specific language governing permissions and 14 | // * limitations under the License. 15 | // */ 16 | // 17 | //package com.shapesecurity.shift.minifier.passes.reduction; 18 | // 19 | //import Statement; 20 | //import com.shapesecurity.shift.ast.statement.BlockStatement; 21 | //import com.shapesecurity.shift.ast.statement.EmptyStatement; 22 | //import com.shapesecurity.shift.minifier.ReductionRule; 23 | //import com.shapesecurity.shift.visitor.DirtyState; 24 | // 25 | //import javax.annotation.Nonnull; 26 | // 27 | //public class RemoveEmptyBlocks extends ReductionRule { 28 | // /* replace empty blocks with empty statements */ 29 | // public static final RemoveEmptyBlocks INSTANCE = new RemoveEmptyBlocks(); 30 | // 31 | // @Nonnull 32 | // @Override 33 | // public DirtyState transform(@Nonnull BlockStatement node) { 34 | // return node.block.statements.isEmpty() ? DirtyState.dirty(new EmptyStatement()) : DirtyState.clean(node); 35 | // } 36 | //} 37 | -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/minifier/passes/reduction/RemoveEmptyTrailingDefault.java: -------------------------------------------------------------------------------- 1 | ///* 2 | // * Copyright 2014 Shape Security, Inc. 3 | // * 4 | // * Licensed under the Apache License, Version 2.0 (the "License"); 5 | // * you may not use this file except in compliance with the License. 6 | // * You may obtain a copy of the License at 7 | // * 8 | // * http://www.apache.org/licenses/LICENSE-2.0 9 | // * 10 | // * Unless required by applicable law or agreed to in writing, software 11 | // * distributed under the License is distributed on an "AS IS" BASIS, 12 | // * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // * See the License for the specific language governing permissions and 14 | // * limitations under the License. 15 | // */ 16 | // 17 | //package com.shapesecurity.shift.minifier.passes.reduction; 18 | // 19 | //import Statement; 20 | //import com.shapesecurity.shift.ast.statement.SwitchStatement; 21 | //import com.shapesecurity.shift.ast.statement.SwitchStatementWithDefault; 22 | //import com.shapesecurity.shift.minifier.ReductionRule; 23 | //import com.shapesecurity.shift.visitor.DirtyState; 24 | // 25 | //import javax.annotation.Nonnull; 26 | // 27 | //public class RemoveEmptyTrailingDefault extends ReductionRule { 28 | // /* remove SwitchDefault when its consequent is empty and it is the last SwitchCase */ 29 | // public static final RemoveEmptyTrailingDefault INSTANCE = new RemoveEmptyTrailingDefault(); 30 | // 31 | // @Nonnull 32 | // @Override 33 | // public DirtyState transform(@Nonnull final SwitchStatementWithDefault node) { 34 | // if (node.defaultCase.consequent.isEmpty() && node.postDefaultCases.isEmpty()) { 35 | // return DirtyState.dirty(new SwitchStatement(node.discriminant, node.preDefaultCases)); 36 | // } 37 | // return DirtyState.clean(node); 38 | // } 39 | //} 40 | -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/minifier/passes/reduction/RemoveSingleStatementBlocks.java: -------------------------------------------------------------------------------- 1 | ///* 2 | // * Copyright 2014 Shape Security, Inc. 3 | // * 4 | // * Licensed under the Apache License, Version 2.0 (the "License"); 5 | // * you may not use this file except in compliance with the License. 6 | // * You may obtain a copy of the License at 7 | // * 8 | // * http://www.apache.org/licenses/LICENSE-2.0 9 | // * 10 | // * Unless required by applicable law or agreed to in writing, software 11 | // * distributed under the License is distributed on an "AS IS" BASIS, 12 | // * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // * See the License for the specific language governing permissions and 14 | // * limitations under the License. 15 | // */ 16 | // 17 | //package com.shapesecurity.shift.minifier.passes.reduction; 18 | // 19 | //import Statement; 20 | //import com.shapesecurity.shift.ast.statement.BlockStatement; 21 | //import com.shapesecurity.shift.minifier.ReductionRule; 22 | //import com.shapesecurity.shift.visitor.DirtyState; 23 | // 24 | //import javax.annotation.Nonnull; 25 | // 26 | //public class RemoveSingleStatementBlocks extends ReductionRule { 27 | // /* replace single-statement blocks with the contained statement */ 28 | // public static final RemoveSingleStatementBlocks INSTANCE = new RemoveSingleStatementBlocks(); 29 | // 30 | // @Nonnull 31 | // @Override 32 | // public DirtyState transform(@Nonnull BlockStatement node) { 33 | // return node.block.statements.isNotEmpty() && node.block.statements.maybeTail().fromJust().isEmpty() ? DirtyState.dirty( 34 | // node.block.statements.maybeHead().fromJust()) : DirtyState.clean(node); 35 | // } 36 | //} 37 | -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/minifier/passes/reduction/ReplaceWhileWithFor.java: -------------------------------------------------------------------------------- 1 | ///* 2 | // * Copyright 2014 Shape Security, Inc. 3 | // * 4 | // * Licensed under the Apache License, Version 2.0 (the "License"); 5 | // * you may not use this file except in compliance with the License. 6 | // * You may obtain a copy of the License at 7 | // * 8 | // * http://www.apache.org/licenses/LICENSE-2.0 9 | // * 10 | // * Unless required by applicable law or agreed to in writing, software 11 | // * distributed under the License is distributed on an "AS IS" BASIS, 12 | // * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // * See the License for the specific language governing permissions and 14 | // * limitations under the License. 15 | // */ 16 | // 17 | //package com.shapesecurity.shift.minifier.passes.reduction; 18 | // 19 | //import com.shapesecurity.functional.data.Maybe; 20 | //import Statement; 21 | //import com.shapesecurity.shift.ast.statement.ForStatement; 22 | //import com.shapesecurity.shift.ast.statement.WhileStatement; 23 | //import com.shapesecurity.shift.minifier.ReductionRule; 24 | //import com.shapesecurity.shift.visitor.DirtyState; 25 | // 26 | //import javax.annotation.Nonnull; 27 | // 28 | //public class ReplaceWhileWithFor extends ReductionRule { 29 | // /* for any X and Y, replace while(X)Y with for(;X;)Y */ 30 | // public static final ReplaceWhileWithFor INSTANCE = new ReplaceWhileWithFor(); 31 | // 32 | // @Nonnull 33 | // @Override 34 | // public DirtyState transform(@Nonnull WhileStatement node) { 35 | // return DirtyState.dirty(new ForStatement(Maybe.empty(), Maybe.of(node.test), Maybe.empty(), 36 | // node.body)); 37 | // } 38 | //} 39 | -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/parser/EarlyError.java: -------------------------------------------------------------------------------- 1 | package com.shapesecurity.shift.es2018.parser; 2 | 3 | import com.shapesecurity.shift.es2018.ast.Node; 4 | 5 | import javax.annotation.Nonnull; 6 | 7 | public class EarlyError { 8 | @Nonnull 9 | public final Node node; 10 | @Nonnull 11 | public final String message; 12 | 13 | public EarlyError(@Nonnull Node node, @Nonnull String message) { 14 | this.node = node; 15 | this.message = message; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/parser/JsError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Shape Security, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.shapesecurity.shift.es2018.parser; 18 | 19 | public class JsError extends Exception { 20 | private static final long serialVersionUID = -5526903161079226322L; 21 | private final int index, line, column; 22 | private final String description; 23 | 24 | public JsError(int index, int line, int column, String description) { 25 | super(); 26 | this.index = index; 27 | this.line = line; 28 | this.column = column; 29 | this.description = description; 30 | } 31 | 32 | public int getIndex() { 33 | return this.index; 34 | } 35 | 36 | public int getLine() { 37 | return this.line; 38 | } 39 | 40 | public int getColumn() { 41 | return this.column; 42 | } 43 | 44 | public String getDescription() { 45 | return this.description; 46 | } 47 | 48 | @Override 49 | public String getMessage() { 50 | return String.format("JavaScript error: Line %d Column %d (Index = %d), %s.", this.line, this.column, this.index, 51 | this.description); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/parser/Located.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Shape Security, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.shapesecurity.shift.es2018.parser; 18 | 19 | import javax.annotation.Nonnull; 20 | import javax.annotation.Nullable; 21 | 22 | public class Located { 23 | 24 | @Nullable 25 | private SourceLocation loc; 26 | 27 | void setLoc(@Nonnull SourceLocation loc) { 28 | this.loc = loc; 29 | } 30 | 31 | @Nullable 32 | public SourceLocation getLoc() { 33 | return loc; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/parser/Parser.java: -------------------------------------------------------------------------------- 1 | package com.shapesecurity.shift.es2018.parser; 2 | 3 | import com.shapesecurity.functional.Unit; 4 | import com.shapesecurity.shift.es2018.ast.Module; 5 | import com.shapesecurity.shift.es2018.ast.Node; 6 | import com.shapesecurity.shift.es2018.ast.Script; 7 | import javax.annotation.Nonnull; 8 | 9 | public class Parser extends GenericParser { 10 | 11 | protected Parser(@Nonnull String source, boolean isModule) throws JsError { 12 | super(source, isModule); 13 | } 14 | 15 | @Nonnull 16 | public static Script parseScript(@Nonnull String text) throws JsError { 17 | return new Parser(text, false).parseScript(); 18 | } 19 | 20 | @Nonnull 21 | public static Module parseModule(@Nonnull String text) throws JsError { 22 | return new Parser(text, true).parseModule(); 23 | } 24 | 25 | @Nonnull 26 | @Override 27 | protected T finishNode(@Nonnull Unit startState, @Nonnull T node) { 28 | return node; 29 | } 30 | 31 | @Nonnull 32 | @Override 33 | protected Unit startNode() { 34 | return Unit.unit; 35 | } 36 | 37 | @Nonnull 38 | @Override 39 | protected T copyNode(@Nonnull Node src, @Nonnull T dest) { 40 | return dest; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/parser/README.md: -------------------------------------------------------------------------------- 1 | Shift AST Parser 2 | ================ 3 | 4 | ## Description 5 | 6 | The `Parser.parseScript` function parses a String of ECMAScript program text using `Script` as the goal symbol, and either returns a `Script` node or throws a `ParseError`. Similarly, the `Parser.parseModule` function parses a String of ECMAScript program text using `Module` as the goal symbol, and either returns a `Module` node or throws a `ParseError`. 7 | 8 | ## Usage 9 | 10 | ```java 11 | import com.shapesecurity.shift.parser.Parser; 12 | 13 | String js = "a; b;"; 14 | Script p = Parser.parseScript(js); 15 | Module m = Parser.parseModule(js); 16 | ``` 17 | -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/parser/SourceLocation.java: -------------------------------------------------------------------------------- 1 | package com.shapesecurity.shift.es2018.parser; 2 | 3 | import com.shapesecurity.functional.data.HashCodeBuilder; 4 | import javax.annotation.Nonnull; 5 | 6 | public class SourceLocation { 7 | @Nonnull 8 | public final Integer line; 9 | @Nonnull 10 | public final Integer column; 11 | @Nonnull 12 | public final Integer offset; 13 | 14 | public SourceLocation(@Nonnull Integer line, @Nonnull Integer column, @Nonnull Integer offset) { 15 | super(); 16 | this.line = line; 17 | this.column = column; 18 | this.offset = offset; 19 | } 20 | 21 | @Override 22 | public boolean equals(Object object) { 23 | return object instanceof SourceLocation && this.line.equals(((SourceLocation) object).line) && 24 | this.column.equals(((SourceLocation) object).column) && this.offset.equals( 25 | ((SourceLocation) object).offset); 26 | } 27 | 28 | @Override 29 | public int hashCode() { 30 | int code = HashCodeBuilder.put(0, "SourceLocation"); 31 | code = HashCodeBuilder.put(code, this.line); 32 | code = HashCodeBuilder.put(code, this.column); 33 | code = HashCodeBuilder.put(code, this.offset); 34 | return code; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/parser/SourceSpan.java: -------------------------------------------------------------------------------- 1 | package com.shapesecurity.shift.es2018.parser; 2 | 3 | import com.shapesecurity.functional.data.HashCodeBuilder; 4 | import com.shapesecurity.functional.data.Maybe; 5 | import javax.annotation.Nonnull; 6 | 7 | public class SourceSpan { 8 | @Nonnull 9 | public final Maybe source; 10 | @Nonnull 11 | public final SourceLocation start; 12 | @Nonnull 13 | public final SourceLocation end; 14 | 15 | public SourceSpan(@Nonnull Maybe source, @Nonnull SourceLocation start, @Nonnull SourceLocation end) { 16 | this.source = source; 17 | this.start = start; 18 | this.end = end; 19 | } 20 | 21 | @Override 22 | public boolean equals(Object object) { 23 | return object instanceof SourceSpan && this.source.equals(((SourceSpan) object).source) && this.start.equals( 24 | ((SourceSpan) object).start) && this.end.equals(((SourceSpan) object).end); 25 | } 26 | 27 | @Override 28 | public int hashCode() { 29 | int code = HashCodeBuilder.put(0, "SourceSpan"); 30 | code = HashCodeBuilder.put(code, this.source); 31 | code = HashCodeBuilder.put(code, this.start); 32 | code = HashCodeBuilder.put(code, this.end); 33 | return code; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/parser/Token.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Shape Security, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.shapesecurity.shift.es2018.parser; 18 | 19 | import javax.annotation.Nonnull; 20 | import javax.annotation.Nullable; 21 | 22 | public abstract class Token { 23 | @Nonnull 24 | public final TokenType type; 25 | @Nonnull 26 | public final SourceRange slice; 27 | @Nullable 28 | public SourceRange leadingWhitespace; 29 | 30 | protected Token(@Nonnull TokenType type, 31 | @Nonnull SourceRange slice) { 32 | this.type = type; 33 | this.slice = slice; 34 | } 35 | 36 | @Nonnull 37 | public abstract CharSequence getValueString(); 38 | 39 | @Override 40 | @Nonnull 41 | public String toString() { 42 | return this.slice.getString().toString(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/parser/TokenClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Shape Security, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.shapesecurity.shift.es2018.parser; 18 | 19 | import javax.annotation.Nonnull; 20 | 21 | public enum TokenClass { 22 | BooleanLiteral("Boolean"), 23 | Eof(""), 24 | Ident("Identifier"), 25 | Keyword("Keyword"), 26 | NullLiteral("Null"), 27 | NumericLiteral("Numeric"), 28 | Punctuator("Punctuator"), 29 | StringLiteral("String"), 30 | RegularExpression("RegularExpression"), 31 | LineComment("Line"), 32 | BlockComment("Block"), 33 | Illegal("Illegal"), 34 | TemplateElement("Template"); 35 | private final String name; 36 | 37 | private TokenClass(String name) { 38 | this.name = name; 39 | } 40 | 41 | @Nonnull 42 | public String getName() { 43 | return this.name; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/parser/TokenizerState.java: -------------------------------------------------------------------------------- 1 | package com.shapesecurity.shift.es2018.parser; 2 | 3 | import javax.annotation.Nonnull; 4 | 5 | public class TokenizerState { 6 | @Nonnull 7 | public final int index; 8 | public final int line; 9 | public final int lineStart; 10 | public final int startIndex; 11 | public final int startLine; 12 | public final int startLineStart; 13 | public final int lastLine; 14 | public final int lastLineStart; 15 | public final int lastIndex; 16 | @Nonnull 17 | public final Token lookahead; 18 | public final boolean hasLineTerminatorBeforeNext; 19 | 20 | public TokenizerState( 21 | int index, 22 | int line, 23 | int lineStart, 24 | int startIndex, 25 | int startLine, 26 | int startLineStart, 27 | int lastIndex, 28 | int lastLine, 29 | int lastLineStart, 30 | @Nonnull Token lookahead, 31 | boolean hasLineTerminatorBeforeNext 32 | ) { 33 | this.index = index; 34 | this.line = line; 35 | this.lineStart = lineStart; 36 | this.startIndex = startIndex; 37 | this.startLine = startLine; 38 | this.startLineStart = startLineStart; 39 | this.lastIndex = lastIndex; 40 | this.lastLine = lastLine; 41 | this.lastLineStart = lastLineStart; 42 | this.lookahead = lookahead; 43 | this.hasLineTerminatorBeforeNext = hasLineTerminatorBeforeNext; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/parser/token/EOFToken.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Shape Security, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.shapesecurity.shift.es2018.parser.token; 18 | 19 | import com.shapesecurity.shift.es2018.parser.TokenType; 20 | import com.shapesecurity.shift.es2018.parser.SourceRange; 21 | import com.shapesecurity.shift.es2018.parser.Token; 22 | 23 | import javax.annotation.Nonnull; 24 | 25 | public class EOFToken extends Token { 26 | public EOFToken(@Nonnull SourceRange slice) { 27 | super(TokenType.EOS, slice); 28 | } 29 | 30 | @Nonnull 31 | @Override 32 | public CharSequence getValueString() { 33 | return ""; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/parser/token/FalseLiteralToken.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Shape Security, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.shapesecurity.shift.es2018.parser.token; 18 | 19 | import com.shapesecurity.shift.es2018.parser.TokenType; 20 | import com.shapesecurity.shift.es2018.parser.SourceRange; 21 | 22 | import javax.annotation.Nonnull; 23 | 24 | public class FalseLiteralToken extends IdentifierLikeToken { 25 | public FalseLiteralToken(@Nonnull SourceRange slice) { 26 | super(TokenType.FALSE_LITERAL, slice); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/parser/token/IdentifierLikeToken.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Shape Security, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.shapesecurity.shift.es2018.parser.token; 18 | 19 | import com.shapesecurity.shift.es2018.parser.SourceRange; 20 | import com.shapesecurity.shift.es2018.parser.Token; 21 | import com.shapesecurity.shift.es2018.parser.TokenType; 22 | 23 | import javax.annotation.Nonnull; 24 | 25 | public abstract class IdentifierLikeToken extends Token { 26 | IdentifierLikeToken(@Nonnull TokenType type, @Nonnull SourceRange slice) { 27 | super(type, slice); 28 | } 29 | 30 | @Nonnull 31 | @Override 32 | public CharSequence getValueString() { 33 | return this.slice; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/parser/token/IdentifierToken.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Shape Security, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.shapesecurity.shift.es2018.parser.token; 18 | 19 | import com.shapesecurity.shift.es2018.parser.TokenType; 20 | import com.shapesecurity.shift.es2018.parser.SourceRange; 21 | 22 | import javax.annotation.Nonnull; 23 | 24 | public class IdentifierToken extends IdentifierLikeToken { 25 | 26 | @Nonnull 27 | private final CharSequence name; 28 | public final boolean escaped; 29 | 30 | public IdentifierToken(@Nonnull SourceRange slice, @Nonnull CharSequence name, boolean escaped) { 31 | super(TokenType.IDENTIFIER, slice); 32 | this.name = name; 33 | this.escaped = escaped; 34 | } 35 | 36 | @Override 37 | @Nonnull 38 | public String toString() { 39 | return String.valueOf(this.name); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/parser/token/KeywordToken.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Shape Security, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.shapesecurity.shift.es2018.parser.token; 18 | 19 | import com.shapesecurity.shift.es2018.parser.TokenType; 20 | import com.shapesecurity.shift.es2018.parser.SourceRange; 21 | 22 | import javax.annotation.Nonnull; 23 | 24 | public class KeywordToken extends IdentifierLikeToken { 25 | 26 | @Nonnull 27 | public final CharSequence identifier; 28 | 29 | public KeywordToken(@Nonnull TokenType type, @Nonnull SourceRange slice, @Nonnull CharSequence identifier) { 30 | super(type, slice); 31 | this.identifier = identifier; 32 | } 33 | 34 | @Override 35 | @Nonnull 36 | public String toString() { 37 | return String.valueOf(this.identifier); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/parser/token/NullLiteralToken.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Shape Security, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.shapesecurity.shift.es2018.parser.token; 18 | 19 | import com.shapesecurity.shift.es2018.parser.TokenType; 20 | import com.shapesecurity.shift.es2018.parser.SourceRange; 21 | 22 | import javax.annotation.Nonnull; 23 | 24 | public final class NullLiteralToken extends IdentifierLikeToken { 25 | public NullLiteralToken(@Nonnull SourceRange slice) { 26 | super(TokenType.NULL_LITERAL, slice); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/parser/token/NumericLiteralToken.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Shape Security, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.shapesecurity.shift.es2018.parser.token; 18 | 19 | import com.shapesecurity.shift.es2018.parser.TokenType; 20 | import com.shapesecurity.shift.es2018.utils.D2A; 21 | import com.shapesecurity.shift.es2018.parser.SourceRange; 22 | import com.shapesecurity.shift.es2018.parser.Token; 23 | 24 | import javax.annotation.Nonnull; 25 | 26 | public final class NumericLiteralToken extends Token { 27 | public final double value; 28 | public final boolean octal; 29 | public final boolean noctal; 30 | 31 | public NumericLiteralToken(@Nonnull SourceRange slice, double value) { 32 | this(slice, value, false, false); 33 | } 34 | 35 | public NumericLiteralToken(@Nonnull SourceRange slice, double value, boolean octal, boolean noctal) { 36 | super(TokenType.NUMBER, slice); 37 | this.value = value; 38 | this.octal = octal; 39 | this.noctal = octal && noctal; 40 | } 41 | 42 | @Nonnull 43 | @Override 44 | public String getValueString() { 45 | return D2A.d2a(this.value); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/parser/token/PunctuatorToken.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Shape Security, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.shapesecurity.shift.es2018.parser.token; 18 | 19 | import com.shapesecurity.shift.es2018.parser.TokenType; 20 | import com.shapesecurity.shift.es2018.parser.SourceRange; 21 | import com.shapesecurity.shift.es2018.parser.Token; 22 | 23 | import javax.annotation.Nonnull; 24 | 25 | public class PunctuatorToken extends Token { 26 | public PunctuatorToken(@Nonnull TokenType type, @Nonnull SourceRange slice) { 27 | super(type, slice); 28 | } 29 | 30 | @Nonnull 31 | @Override 32 | public String getValueString() { 33 | return this.type.name; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/parser/token/RegularExpressionLiteralToken.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Shape Security, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.shapesecurity.shift.es2018.parser.token; 18 | 19 | import com.shapesecurity.shift.es2018.parser.SourceRange; 20 | import com.shapesecurity.shift.es2018.parser.Token; 21 | import com.shapesecurity.shift.es2018.parser.TokenType; 22 | 23 | import javax.annotation.Nonnull; 24 | 25 | public class RegularExpressionLiteralToken extends Token { 26 | @Nonnull 27 | private final String value; 28 | 29 | public RegularExpressionLiteralToken(@Nonnull SourceRange slice, @Nonnull String value) { 30 | super(TokenType.REGEXP, slice); 31 | this.value = value; 32 | } 33 | 34 | @Nonnull 35 | @Override 36 | public String getValueString() { 37 | return this.value; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/parser/token/StringLiteralToken.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Shape Security, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.shapesecurity.shift.es2018.parser.token; 18 | 19 | import com.shapesecurity.shift.es2018.parser.TokenType; 20 | import com.shapesecurity.shift.es2018.parser.SourceRange; 21 | import com.shapesecurity.shift.es2018.parser.Token; 22 | 23 | import javax.annotation.Nonnull; 24 | 25 | public class StringLiteralToken extends Token { 26 | private final String value; 27 | public final String octal; 28 | 29 | public StringLiteralToken(@Nonnull SourceRange slice, @Nonnull String value, String octal) { 30 | super(TokenType.STRING, slice); 31 | this.value = value; 32 | this.octal = octal; 33 | } 34 | 35 | @Nonnull 36 | @Override 37 | public String getValueString() { 38 | return this.value; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/parser/token/TemplateToken.java: -------------------------------------------------------------------------------- 1 | package com.shapesecurity.shift.es2018.parser.token; 2 | 3 | import com.shapesecurity.shift.es2018.parser.TokenType; 4 | import com.shapesecurity.shift.es2018.parser.SourceRange; 5 | import com.shapesecurity.shift.es2018.parser.Token; 6 | 7 | import javax.annotation.Nonnull; 8 | 9 | public final class TemplateToken extends Token { 10 | 11 | public final boolean tail; 12 | 13 | public TemplateToken(@Nonnull SourceRange slice, boolean tail) { 14 | super(TokenType.TEMPLATE, slice); 15 | this.tail = tail; 16 | } 17 | 18 | @Nonnull 19 | @Override 20 | public CharSequence getValueString() { 21 | return this.slice; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/parser/token/TrueLiteralToken.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Shape Security, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.shapesecurity.shift.es2018.parser.token; 18 | 19 | import com.shapesecurity.shift.es2018.parser.TokenType; 20 | import com.shapesecurity.shift.es2018.parser.SourceRange; 21 | 22 | import javax.annotation.Nonnull; 23 | 24 | public class TrueLiteralToken extends IdentifierLikeToken { 25 | public TrueLiteralToken(@Nonnull SourceRange slice) { 26 | super(TokenType.TRUE_LITERAL, slice); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/reducer/Flattener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Shape Security, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | 18 | package com.shapesecurity.shift.es2018.reducer; 19 | 20 | import com.shapesecurity.functional.data.ConcatList; 21 | import com.shapesecurity.functional.data.ImmutableList; 22 | import com.shapesecurity.functional.data.Monoid; 23 | import com.shapesecurity.shift.es2018.ast.Node; 24 | import com.shapesecurity.shift.es2018.ast.Program; 25 | 26 | import javax.annotation.Nonnull; 27 | 28 | public class Flattener { 29 | private static final Reducer> INSTANCE = new WrappedReducer<>( 30 | (node, nodes) -> ConcatList.of(node).append(nodes), 31 | new MonoidalReducer<>(new Monoid.ConcatListAppend<>()) 32 | ); 33 | 34 | private Flattener() {} 35 | 36 | @Nonnull 37 | public static ImmutableList flatten(@Nonnull Program program) { 38 | return Director.reduceProgram(INSTANCE, program).toList(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/reducer/MultiMonoidalReducer.java: -------------------------------------------------------------------------------- 1 | package com.shapesecurity.shift.es2018.reducer; 2 | 3 | import com.shapesecurity.functional.Pair; 4 | import com.shapesecurity.functional.data.FreePairingMonoid; 5 | import com.shapesecurity.functional.data.Monoid; 6 | 7 | import javax.annotation.Nonnull; 8 | 9 | public class MultiMonoidalReducer extends MonoidalReducer> { 10 | public MultiMonoidalReducer(@Nonnull Monoid> stateMonoid) { 11 | super(stateMonoid); 12 | } 13 | 14 | public static MultiMonoidalReducer from(@Nonnull Monoid monoidA, @Nonnull Monoid monoidB) { 15 | return new MultiMonoidalReducer<>(new FreePairingMonoid<>(monoidA, monoidB)); 16 | } 17 | 18 | public static MultiMonoidalReducer> from(@Nonnull Monoid monoidA, @Nonnull Monoid monoidB, @Nonnull Monoid monoidC) { 19 | return new MultiMonoidalReducer<>(new FreePairingMonoid<>(monoidA, new FreePairingMonoid<>(monoidB, monoidC))); 20 | } 21 | 22 | public static MultiMonoidalReducer>> from(@Nonnull Monoid monoidA, @Nonnull Monoid monoidB, @Nonnull Monoid monoidC, @Nonnull Monoid monoidD) { 23 | return new MultiMonoidalReducer<>(new FreePairingMonoid<>(monoidA, new FreePairingMonoid<>(monoidB, new FreePairingMonoid<>(monoidC, monoidD)))); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/reducer/disabled/Transformer.java: -------------------------------------------------------------------------------- 1 | ///* 2 | // * Copyright 2014 Shape Security, Inc. 3 | // * 4 | // * Licensed under the Apache License, Version 2.0 (the "License"); 5 | // * you may not use this file except in compliance with the License. 6 | // * You may obtain a copy of the License at 7 | // * 8 | // * http://www.apache.org/licenses/LICENSE-2.0 9 | // * 10 | // * Unless required by applicable law or agreed to in writing, software 11 | // * distributed under the License is distributed on an "AS IS" BASIS, 12 | // * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // * See the License for the specific language governing permissions and 14 | // * limitations under the License. 15 | // */ 16 | // 17 | //package com.shapesecurity.shift.visitor.disabled; 18 | // 19 | //public interface Transformer 20 | // extends TransformerP { 21 | //} 22 | -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/scope/Accessibility.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Shape Security, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.shapesecurity.shift.es2018.scope; 18 | 19 | public enum Accessibility { 20 | Read, 21 | Write, 22 | ReadWrite; 23 | 24 | public final boolean isRead() { 25 | return this == Read || this == ReadWrite; 26 | } 27 | 28 | public final boolean isWrite() { 29 | return this == Write || this == ReadWrite; 30 | } 31 | 32 | public final boolean isReadWrite() { 33 | return this == ReadWrite; 34 | } 35 | 36 | public final Accessibility withReadability() { 37 | return this == Read ? this : ReadWrite; 38 | } 39 | 40 | public final Accessibility withWritability() { 41 | return this == Write ? this : ReadWrite; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/scope/README.md: -------------------------------------------------------------------------------- 1 | Shift AST Scope Analyzer 2 | =============================== 3 | 4 | ## Description 5 | 6 | The `ScopeAnalyzer` class collects variable scoping information into a scope tree. 7 | 8 | 9 | ## Usage 10 | ``` 11 | import com.shapesecurity.shift.parser.Parser; 12 | import com.shapesecurity.shift.ast.Program; 13 | import com.shapesecurity.shift.scope.ScopeAnalyzer; 14 | import com.shapesecurity.shift.scope.GlobalScope; 15 | 16 | String source = "a; b;"; 17 | Script program = Parser.parse(source); 18 | GlobalScope global = ScopeAnalyzer.analyze(program); 19 | 20 | // look at the top-level variables 21 | 22 | // list the implicit globals (global throughs) 23 | 24 | ``` 25 | -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/scope/Variable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Shape Security, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.shapesecurity.shift.es2018.scope; 18 | 19 | import com.shapesecurity.functional.data.ImmutableList; 20 | 21 | import javax.annotation.Nonnull; 22 | 23 | public class Variable { 24 | /** 25 | * Variable name * 26 | */ 27 | @Nonnull 28 | public final String name; 29 | /** 30 | * references of this variable * 31 | */ 32 | @Nonnull 33 | public final ImmutableList references; 34 | /** 35 | * declarations of this variable * 36 | */ 37 | @Nonnull 38 | public final ImmutableList declarations; 39 | 40 | public Variable( 41 | @Nonnull String name, 42 | @Nonnull ImmutableList references, 43 | @Nonnull ImmutableList declarations) { 44 | this.name = name; 45 | this.references = references; 46 | this.declarations = declarations; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/template/README.md: -------------------------------------------------------------------------------- 1 | # Shift Templates 2 | 3 | This class provides a templating system for JavaScript programs. 4 | 5 | See [the JavaScript project](https://github.com/shapesecurity/shift-template-js) for more description. 6 | 7 | ## Java-specific notes 8 | 9 | The main difference from the JavaScript implementation is the TemplateValues class, which is used to instantiated structured templates. 10 | 11 | This class is constructed with three maps, each going from labels to boolean conditions, to lists of TemplateValues objects to be used in loops, and to Function replacement functions. For example: 12 | 13 | ```java 14 | String source = "" + 15 | "f(" + 16 | " /*# for each x of xs #*/" + 17 | " /*# x::arg #*/ replaceme," + 18 | ")"; 19 | 20 | Map conditions = Map.of(); 21 | Map> lists = Map.of( 22 | "xs", 23 | List.of( 24 | new ReduceStructured.TemplateValues( 25 | Map.of(), 26 | Map.of(), 27 | Map.of("arg", node -> new IdentifierExpression("x_1")) 28 | ), 29 | new ReduceStructured.TemplateValues( 30 | Map.of(), 31 | Map.of(), 32 | Map.of("arg", node -> new IdentifierExpression("x_2")) 33 | ) 34 | ) 35 | ); 36 | Map> replacers = Map.of(); 37 | 38 | ReduceStructured.TemplateValues values = new ReduceStructured.TemplateValues(conditions, lists, replacers); 39 | 40 | Template moduleTemplate = Template.fromModuleSource(source); 41 | Program result = moduleTemplate.applyStructured(values); 42 | 43 | assertEquals(Parser.parseModule("f(x_1, x_2)"), result); 44 | ``` -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/utils/WithLocation.java: -------------------------------------------------------------------------------- 1 | package com.shapesecurity.shift.es2018.utils; 2 | 3 | import com.shapesecurity.functional.data.Maybe; 4 | import com.shapesecurity.shift.es2018.ast.Node; 5 | import com.shapesecurity.shift.es2018.parser.SourceSpan; 6 | 7 | import javax.annotation.Nonnull; 8 | 9 | public interface WithLocation { 10 | @Nonnull 11 | Maybe getLocation(@Nonnull Node node); 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/validator/README.md: -------------------------------------------------------------------------------- 1 | Shift AST Validator 2 | =========================== 3 | 4 | ## Description 5 | 6 | The `Validator.validate` function validates an AST and returns a list of validation errors. 7 | 8 | ## Usage 9 | 10 | ```java 11 | import com.shapesecurity.shift.parser.Parser; 12 | import com.shapesecurity.shift.ast.Program; 13 | import com.shapesecurity.shift.scope.ScopeAnalyzer; 14 | import com.shapesecurity.shift.js.valid.Validator; 15 | import com.shapesecurity.shift.js.valid.ValidationError; 16 | 17 | String source = "a; b;"; 18 | Script script = new Parser(source).parse(); 19 | List errs = Validator.validate(script); 20 | ``` 21 | -------------------------------------------------------------------------------- /src/main/java/com/shapesecurity/shift/es2018/validator/ValidationError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Shape Security, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.shapesecurity.shift.es2018.validator; 18 | 19 | import com.shapesecurity.shift.es2018.ast.Node; 20 | 21 | import javax.annotation.Nonnull; 22 | 23 | public class ValidationError { 24 | @Nonnull 25 | public final Node node; 26 | @Nonnull 27 | public final String message; 28 | 29 | public ValidationError(@Nonnull Node node, @Nonnull String message) { 30 | this.node = node; 31 | this.message = message; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/com/shapesecurity/shift/es2018/others/TestReducer.java: -------------------------------------------------------------------------------- 1 | ///* 2 | // * Copyright 2014 Shape Security, Inc. 3 | // * 4 | // * Licensed under the Apache License, Version 2.0 (the "License"); 5 | // * you may not use this file except in compliance with the License. 6 | // * You may obtain a copy of the License at 7 | // * 8 | // * http://www.apache.org/licenses/LICENSE-2.0 9 | // * 10 | // * Unless required by applicable law or agreed to in writing, software 11 | // * distributed under the License is distributed on an "AS IS" BASIS, 12 | // * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // * See the License for the specific language governing permissions and 14 | // * limitations under the License. 15 | // */ 16 | // 17 | //package com.shapesecurity.shift.others; 18 | // 19 | //import javax.annotation.Nonnull; 20 | // 21 | //import com.shapesecurity.functional.data.ImmutableList; 22 | //import Node; 23 | //import Branch; 24 | // 25 | //public abstract class TestReducer extends TestReducerWithPath { 26 | // 27 | // protected abstract void accept(@Nonnull Node node); 28 | // 29 | // @Override 30 | // protected void accept(@Nonnull Node node, @Nonnull ImmutableList path) { 31 | // accept(node); 32 | // } 33 | //} 34 | -------------------------------------------------------------------------------- /src/test/java/com/shapesecurity/shift/es2018/parser/API/ModuleTest.java: -------------------------------------------------------------------------------- 1 | package com.shapesecurity.shift.es2018.parser.API; 2 | 3 | import com.shapesecurity.functional.data.ImmutableList; 4 | import com.shapesecurity.shift.es2018.ast.Module; 5 | import com.shapesecurity.shift.es2018.parser.ParserTestCase; 6 | import com.shapesecurity.shift.es2018.parser.JsError; 7 | 8 | import org.junit.Test; 9 | 10 | public class ModuleTest extends ParserTestCase { 11 | @Test 12 | public void testModule() throws JsError { 13 | testModule("", new Module(ImmutableList.empty(), ImmutableList.empty())); 14 | testModuleFailure("/*", 2, "Unexpected end of input"); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/test/java/com/shapesecurity/shift/es2018/parser/API/ScriptTest.java: -------------------------------------------------------------------------------- 1 | package com.shapesecurity.shift.es2018.parser.API; 2 | 3 | import com.shapesecurity.functional.data.ImmutableList; 4 | import com.shapesecurity.shift.es2018.ast.Script; 5 | import com.shapesecurity.shift.es2018.parser.JsError; 6 | import com.shapesecurity.shift.es2018.parser.ParserTestCase; 7 | 8 | import org.junit.Test; 9 | 10 | public class ScriptTest extends ParserTestCase { 11 | @Test 12 | public void testScript() throws JsError { 13 | testScript("", new Script(ImmutableList.empty(), ImmutableList.empty())); 14 | testScript(" ", new Script(ImmutableList.empty(), ImmutableList.empty())); 15 | testScriptFailure("/*", 2, "Unexpected end of input"); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/test/java/com/shapesecurity/shift/es2018/parser/ParserTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Shape Security, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.shapesecurity.shift.es2018.parser; 18 | 19 | import com.shapesecurity.shift.es2018.ast.ExpressionStatement; 20 | import com.shapesecurity.shift.es2018.ast.Script; 21 | import com.shapesecurity.shift.es2018.ast.Statement; 22 | import com.shapesecurity.shift.es2018.ast.ThisExpression; 23 | 24 | import org.junit.Test; 25 | 26 | import static org.junit.Assert.assertEquals; 27 | import static org.junit.Assert.assertTrue; 28 | 29 | public class ParserTest { 30 | 31 | @Test 32 | public void testSimple() throws JsError { 33 | Script node = Parser.parseScript("this"); 34 | assertEquals(1, node.statements.length); 35 | Statement stmt = node.statements.maybeHead().fromJust(); 36 | assertTrue(stmt instanceof ExpressionStatement); 37 | assertTrue(((ExpressionStatement) stmt).expression instanceof ThisExpression); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/com/shapesecurity/shift/es2018/parser/declarations/ClassDeclarationTest.java: -------------------------------------------------------------------------------- 1 | package com.shapesecurity.shift.es2018.parser.declarations; 2 | 3 | import com.shapesecurity.functional.data.ImmutableList; 4 | import com.shapesecurity.functional.data.Maybe; 5 | import com.shapesecurity.shift.es2018.ast.BindingIdentifier; 6 | import com.shapesecurity.shift.es2018.ast.ClassDeclaration; 7 | import com.shapesecurity.shift.es2018.parser.ParserTestCase; 8 | import com.shapesecurity.shift.es2018.parser.JsError; 9 | 10 | import org.junit.Test; 11 | 12 | public class ClassDeclarationTest extends ParserTestCase { 13 | @Test 14 | public void testClassDeclarations() throws JsError { 15 | testScript("class A{}", new ClassDeclaration(new BindingIdentifier("A"), Maybe.empty(), ImmutableList.empty())); 16 | 17 | testScriptFailure("class {}", 6, "Unexpected token \"{\""); 18 | testScriptFailure("class extends A{}", 6, "Unexpected token \"extends\""); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/test/java/com/shapesecurity/shift/es2018/parser/destructuring/binding_pattern/BindingIdentifierTest.java: -------------------------------------------------------------------------------- 1 | package com.shapesecurity.shift.es2018.parser.destructuring.binding_pattern; 2 | 3 | import com.shapesecurity.shift.es2018.ast.AssignmentTargetIdentifier; 4 | import com.shapesecurity.shift.es2018.ast.EmptyStatement; 5 | import com.shapesecurity.shift.es2018.ast.ForInStatement; 6 | import com.shapesecurity.shift.es2018.ast.LiteralNumericExpression; 7 | import com.shapesecurity.shift.es2018.parser.JsError; 8 | import com.shapesecurity.shift.es2018.parser.ParserTestCase; 9 | 10 | import org.junit.Test; 11 | 12 | public class BindingIdentifierTest extends ParserTestCase { 13 | @Test 14 | public void testBindingIdentifier() throws JsError { 15 | testScript("for(let in 0);", new ForInStatement(new AssignmentTargetIdentifier("let"), new LiteralNumericExpression(0.0), 16 | new EmptyStatement())); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/com/shapesecurity/shift/es2018/parser/expressions/ConditionalExpressionTest.java: -------------------------------------------------------------------------------- 1 | package com.shapesecurity.shift.es2018.parser.expressions; 2 | 3 | import com.shapesecurity.shift.es2018.ast.AssignmentExpression; 4 | import com.shapesecurity.shift.es2018.ast.BinaryExpression; 5 | import com.shapesecurity.shift.es2018.ast.ConditionalExpression; 6 | import com.shapesecurity.shift.es2018.ast.operators.BinaryOperator; 7 | import com.shapesecurity.shift.es2018.ast.AssignmentTargetIdentifier; 8 | import com.shapesecurity.shift.es2018.ast.IdentifierExpression; 9 | import com.shapesecurity.shift.es2018.ast.LiteralNumericExpression; 10 | import com.shapesecurity.shift.es2018.parser.JsError; 11 | import com.shapesecurity.shift.es2018.parser.ParserTestCase; 12 | 13 | import org.junit.Test; 14 | 15 | public class ConditionalExpressionTest extends ParserTestCase { 16 | @Test 17 | public void testConditionalExpression() throws JsError { 18 | testScript("a?b:c", new ConditionalExpression(new IdentifierExpression("a"), new IdentifierExpression("b"), 19 | new IdentifierExpression("c"))); 20 | 21 | testScript("y ? 1 : 2", new ConditionalExpression(new IdentifierExpression("y"), new LiteralNumericExpression(1.0), 22 | new LiteralNumericExpression(2.0))); 23 | 24 | testScript("x && y ? 1 : 2", new ConditionalExpression(new BinaryExpression( 25 | new IdentifierExpression("x"), BinaryOperator.LogicalAnd, new IdentifierExpression("y")), new LiteralNumericExpression(1.0), 26 | new LiteralNumericExpression(2.0))); 27 | 28 | testScript("x = (0) ? 1 : 2", new AssignmentExpression(new AssignmentTargetIdentifier("x"), new ConditionalExpression( 29 | new LiteralNumericExpression(0.0), new LiteralNumericExpression(1.0), new LiteralNumericExpression(2.0)))); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/com/shapesecurity/shift/es2018/parser/expressions/StaticMemberExpressionTest.java: -------------------------------------------------------------------------------- 1 | package com.shapesecurity.shift.es2018.parser.expressions; 2 | 3 | import com.shapesecurity.shift.es2018.ast.IdentifierExpression; 4 | import com.shapesecurity.shift.es2018.ast.StaticMemberExpression; 5 | import com.shapesecurity.shift.es2018.parser.ParserTestCase; 6 | import com.shapesecurity.shift.es2018.parser.JsError; 7 | 8 | import org.junit.Test; 9 | 10 | public class StaticMemberExpressionTest extends ParserTestCase { 11 | @Test 12 | public void testStaticMemberExpression() throws JsError { 13 | testScript("a.b", new StaticMemberExpression(new IdentifierExpression("a"), "b")); 14 | 15 | testScript("a.b.c", new StaticMemberExpression(new StaticMemberExpression(new IdentifierExpression("a"), "b"), "c")); 16 | 17 | testScript("a.$._.B0", new StaticMemberExpression(new StaticMemberExpression( 18 | new StaticMemberExpression(new IdentifierExpression("a"), "$"), "_"), "B0")); 19 | 20 | testScript("a.if", new StaticMemberExpression(new IdentifierExpression("a"), "if")); 21 | 22 | testScript("a.true", new StaticMemberExpression(new IdentifierExpression("a"), "true")); 23 | 24 | testScript("a.false", new StaticMemberExpression(new IdentifierExpression("a"), "false")); 25 | 26 | testScript("a.null", new StaticMemberExpression(new IdentifierExpression("a"), "null")); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/com/shapesecurity/shift/es2018/parser/expressions/ThisExpressionTest.java: -------------------------------------------------------------------------------- 1 | package com.shapesecurity.shift.es2018.parser.expressions; 2 | 3 | import com.shapesecurity.shift.es2018.ast.ThisExpression; 4 | import com.shapesecurity.shift.es2018.parser.JsError; 5 | import com.shapesecurity.shift.es2018.parser.ParserTestCase; 6 | 7 | import org.junit.Test; 8 | 9 | public class ThisExpressionTest extends ParserTestCase { 10 | 11 | @Test 12 | public void testThisExpression() throws JsError { 13 | testScript("this;", new ThisExpression()); 14 | testModule("this;", new ThisExpression()); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/test/java/com/shapesecurity/shift/es2018/parser/expressions/UnaryExpressionTest.java: -------------------------------------------------------------------------------- 1 | package com.shapesecurity.shift.es2018.parser.expressions; 2 | 3 | import com.shapesecurity.shift.es2018.ast.AssignmentExpression; 4 | import com.shapesecurity.shift.es2018.ast.IdentifierExpression; 5 | import com.shapesecurity.shift.es2018.ast.UnaryExpression; 6 | import com.shapesecurity.shift.es2018.ast.operators.UnaryOperator; 7 | import com.shapesecurity.shift.es2018.ast.AssignmentTargetIdentifier; 8 | import com.shapesecurity.shift.es2018.parser.ParserTestCase; 9 | import com.shapesecurity.shift.es2018.parser.JsError; 10 | 11 | import org.junit.Test; 12 | 13 | public class UnaryExpressionTest extends ParserTestCase { 14 | @Test 15 | public void testUnaryExpression() throws JsError { 16 | testScript("!a", new UnaryExpression(UnaryOperator.LogicalNot, new IdentifierExpression("a"))); 17 | 18 | testScript("!(a=b)", new UnaryExpression(UnaryOperator.LogicalNot, new AssignmentExpression( 19 | new AssignmentTargetIdentifier("a"), new IdentifierExpression("b")))); 20 | 21 | testScript("typeof a", new UnaryExpression(UnaryOperator.Typeof, new IdentifierExpression("a"))); 22 | 23 | testScript("void a", new UnaryExpression(UnaryOperator.Void, new IdentifierExpression("a"))); 24 | 25 | testScript("delete a", new UnaryExpression(UnaryOperator.Delete, new IdentifierExpression("a"))); 26 | 27 | testScript("+a", new UnaryExpression(UnaryOperator.Plus, new IdentifierExpression("a"))); 28 | 29 | testScript("~a", new UnaryExpression(UnaryOperator.BitNot, new IdentifierExpression("a"))); 30 | 31 | testScript("-a", new UnaryExpression(UnaryOperator.Minus, new IdentifierExpression("a"))); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/com/shapesecurity/shift/es2018/parser/expressions/UpdateExpressionTest.java: -------------------------------------------------------------------------------- 1 | package com.shapesecurity.shift.es2018.parser.expressions; 2 | 3 | import com.shapesecurity.shift.es2018.ast.AssignmentTargetIdentifier; 4 | import com.shapesecurity.shift.es2018.ast.UpdateExpression; 5 | import com.shapesecurity.shift.es2018.ast.operators.UpdateOperator; 6 | import com.shapesecurity.shift.es2018.parser.JsError; 7 | import com.shapesecurity.shift.es2018.parser.ParserTestCase; 8 | 9 | import org.junit.Test; 10 | 11 | public class UpdateExpressionTest extends ParserTestCase { 12 | @Test 13 | public void testUpdateExpression() throws JsError { 14 | testScript("++a", new UpdateExpression(true, UpdateOperator.Increment, new AssignmentTargetIdentifier("a"))); 15 | testScript("--a", new UpdateExpression(true, UpdateOperator.Decrement, new AssignmentTargetIdentifier("a"))); 16 | 17 | testScript("x++", new UpdateExpression(false, UpdateOperator.Increment, new AssignmentTargetIdentifier("x"))); 18 | testScript("x--", new UpdateExpression(false, UpdateOperator.Decrement, new AssignmentTargetIdentifier("x"))); 19 | 20 | testScript("eval++", new UpdateExpression(false, UpdateOperator.Increment, new AssignmentTargetIdentifier("eval"))); 21 | testScript("eval--", new UpdateExpression(false, UpdateOperator.Decrement, new AssignmentTargetIdentifier("eval"))); 22 | 23 | testScript("arguments++", new UpdateExpression(false, UpdateOperator.Increment, new AssignmentTargetIdentifier("arguments"))); 24 | testScript("arguments--", new UpdateExpression(false, UpdateOperator.Decrement, new AssignmentTargetIdentifier("arguments"))); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/com/shapesecurity/shift/es2018/parser/expressions/literals/LiteralInfinityExpressionTest.java: -------------------------------------------------------------------------------- 1 | package com.shapesecurity.shift.es2018.parser.expressions.literals; 2 | 3 | import com.shapesecurity.shift.es2018.ast.LiteralInfinityExpression; 4 | import com.shapesecurity.shift.es2018.parser.JsError; 5 | import com.shapesecurity.shift.es2018.parser.ParserTestCase; 6 | 7 | import org.junit.Test; 8 | 9 | public class LiteralInfinityExpressionTest extends ParserTestCase { 10 | @Test 11 | public void testLiteralInfinityExpressionTest() throws JsError { 12 | testScript("2e308", new LiteralInfinityExpression()); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/test/java/com/shapesecurity/shift/es2018/parser/expressions/literals/LiteralNullExpressionTest.java: -------------------------------------------------------------------------------- 1 | package com.shapesecurity.shift.es2018.parser.expressions.literals; 2 | 3 | import com.shapesecurity.shift.es2018.ast.LiteralNullExpression; 4 | import com.shapesecurity.shift.es2018.parser.ParserTestCase; 5 | import com.shapesecurity.shift.es2018.parser.JsError; 6 | 7 | import org.junit.Test; 8 | 9 | public class LiteralNullExpressionTest extends ParserTestCase { 10 | @Test 11 | public void testLiteralNullExpression() throws JsError { 12 | testScript("null", new LiteralNullExpression()); 13 | testScript("null;", new LiteralNullExpression()); 14 | testScript("null\n", new LiteralNullExpression()); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/test/java/com/shapesecurity/shift/es2018/parser/gecko/AsyncAwaitMiscTest.java: -------------------------------------------------------------------------------- 1 | package com.shapesecurity.shift.es2018.parser.gecko; 2 | 3 | import com.shapesecurity.shift.es2018.parser.JsError; 4 | import org.junit.Test; 5 | import static com.shapesecurity.shift.es2018.parser.ParserTestCase.testScriptSuccess; 6 | 7 | public class AsyncAwaitMiscTest { 8 | 9 | @Test 10 | public void test() throws JsError{ 11 | 12 | testScriptSuccess("var expr = async function foo() {\n" + 13 | " return await\n" + 14 | " 10;\n" + 15 | " };"); 16 | 17 | testScriptSuccess("async \n" + 18 | "function a(){}"); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/test/java/com/shapesecurity/shift/es2018/parser/miscellaneous/CommentsTest.java: -------------------------------------------------------------------------------- 1 | package com.shapesecurity.shift.es2018.parser.miscellaneous; 2 | 3 | import com.shapesecurity.shift.es2018.parser.ParserTestCase; 4 | import com.shapesecurity.shift.es2018.parser.JsError; 5 | 6 | import org.junit.Test; 7 | 8 | public class CommentsTest extends ParserTestCase { 9 | @Test 10 | public void testComments() throws JsError { 11 | testScript(" /**/"); 12 | testScript(" /****/"); 13 | testScript(" /**\n\r\r\n**/"); 14 | testScript(" //\n"); 15 | testScript(" comment"); 17 | testScript(" comment"); 19 | testScript(" \t /* block comment */ --> comment"); 20 | testScript("/* block comment */--> comment"); 21 | testScript("0/*\n*/--> a comment"); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/test/java/com/shapesecurity/shift/es2018/parser/statements/BlockStatementTest.java: -------------------------------------------------------------------------------- 1 | package com.shapesecurity.shift.es2018.parser.statements; 2 | 3 | import com.shapesecurity.functional.data.ImmutableList; 4 | import com.shapesecurity.shift.es2018.ast.Block; 5 | import com.shapesecurity.shift.es2018.ast.BlockStatement; 6 | import com.shapesecurity.shift.es2018.ast.CallExpression; 7 | import com.shapesecurity.shift.es2018.ast.ExpressionStatement; 8 | import com.shapesecurity.shift.es2018.ast.IdentifierExpression; 9 | import com.shapesecurity.shift.es2018.parser.ParserTestCase; 10 | import com.shapesecurity.shift.es2018.parser.JsError; 11 | 12 | import org.junit.Test; 13 | 14 | public class BlockStatementTest extends ParserTestCase { 15 | @Test 16 | public void testBlockStatement() throws JsError { 17 | testScript("{ foo }", new BlockStatement(new Block(ImmutableList.of(new ExpressionStatement( 18 | new IdentifierExpression("foo")))))); 19 | 20 | testScript("{ doThis(); doThat(); }", new BlockStatement(new Block(ImmutableList.of( 21 | new ExpressionStatement(new CallExpression(new IdentifierExpression("doThis"), ImmutableList.empty())), 22 | new ExpressionStatement(new CallExpression(new IdentifierExpression("doThat"), ImmutableList.empty())))))); 23 | 24 | testScript("{}", new BlockStatement(new Block(ImmutableList.empty()))); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/com/shapesecurity/shift/es2018/parser/statements/DebuggerStatementTest.java: -------------------------------------------------------------------------------- 1 | package com.shapesecurity.shift.es2018.parser.statements; 2 | 3 | import com.shapesecurity.shift.es2018.ast.DebuggerStatement; 4 | import com.shapesecurity.shift.es2018.parser.JsError; 5 | import com.shapesecurity.shift.es2018.parser.ParserTestCase; 6 | 7 | import org.junit.Test; 8 | 9 | public class DebuggerStatementTest extends ParserTestCase { 10 | @Test 11 | public void testDebuggerStatement() throws JsError { 12 | testScript("debugger", new DebuggerStatement()); 13 | testScript("debugger;", new DebuggerStatement()); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/test/java/com/shapesecurity/shift/es2018/parser/statements/EmptyStatementTest.java: -------------------------------------------------------------------------------- 1 | package com.shapesecurity.shift.es2018.parser.statements; 2 | 3 | import com.shapesecurity.shift.es2018.ast.EmptyStatement; 4 | import com.shapesecurity.shift.es2018.parser.JsError; 5 | import com.shapesecurity.shift.es2018.parser.ParserTestCase; 6 | 7 | import org.junit.Test; 8 | 9 | public class EmptyStatementTest extends ParserTestCase { 10 | @Test 11 | public void testEmptyStatement() throws JsError { 12 | testScript(";", new EmptyStatement()); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/test/java/com/shapesecurity/shift/es2018/parser/statements/ExpressionStatementTest.java: -------------------------------------------------------------------------------- 1 | package com.shapesecurity.shift.es2018.parser.statements; 2 | 3 | import com.shapesecurity.shift.es2018.ast.BinaryExpression; 4 | import com.shapesecurity.shift.es2018.ast.ExpressionStatement; 5 | import com.shapesecurity.shift.es2018.ast.IdentifierExpression; 6 | import com.shapesecurity.shift.es2018.ast.operators.BinaryOperator; 7 | import com.shapesecurity.shift.es2018.parser.ParserTestCase; 8 | import com.shapesecurity.shift.es2018.parser.JsError; 9 | 10 | import org.junit.Test; 11 | 12 | public class ExpressionStatementTest extends ParserTestCase { 13 | @Test 14 | public void testExpressionStatement() throws JsError { 15 | testScript("x", new ExpressionStatement(new IdentifierExpression("x"))); 16 | 17 | testScript("x, y", new ExpressionStatement(new BinaryExpression( 18 | new IdentifierExpression("x"), BinaryOperator.Sequence, new IdentifierExpression("y")))); 19 | 20 | testScript("\\u0061", new ExpressionStatement(new IdentifierExpression("a"))); 21 | 22 | testScript("a\\u0061", new ExpressionStatement(new IdentifierExpression("aa"))); 23 | 24 | testScript("\\u0061a", new ExpressionStatement(new IdentifierExpression("aa"))); 25 | 26 | testScript("\\u0061a ", new ExpressionStatement(new IdentifierExpression("aa"))); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/com/shapesecurity/shift/es2018/parser/statements/ThrowStatementTest.java: -------------------------------------------------------------------------------- 1 | package com.shapesecurity.shift.es2018.parser.statements; 2 | 3 | import com.shapesecurity.functional.data.ImmutableList; 4 | import com.shapesecurity.shift.es2018.ast.BinaryExpression; 5 | import com.shapesecurity.shift.es2018.ast.IdentifierExpression; 6 | import com.shapesecurity.shift.es2018.ast.ObjectExpression; 7 | import com.shapesecurity.shift.es2018.ast.ThrowStatement; 8 | import com.shapesecurity.shift.es2018.ast.operators.BinaryOperator; 9 | import com.shapesecurity.shift.es2018.ast.ThisExpression; 10 | import com.shapesecurity.shift.es2018.parser.ParserTestCase; 11 | import com.shapesecurity.shift.es2018.parser.JsError; 12 | 13 | import org.junit.Test; 14 | 15 | public class ThrowStatementTest extends ParserTestCase { 16 | @Test 17 | public void testThrowStatement() throws JsError { 18 | testScript("throw this", new ThrowStatement(new ThisExpression())); 19 | 20 | testScript("throw x", new ThrowStatement(new IdentifierExpression("x"))); 21 | 22 | testScript("throw x * y", new ThrowStatement(new BinaryExpression(new IdentifierExpression("x"), BinaryOperator.Mul, 23 | new IdentifierExpression("y")))); 24 | 25 | testScript("throw {}", new ThrowStatement(new ObjectExpression(ImmutableList.empty()))); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/test/java/com/shapesecurity/shift/es2018/parser/statements/WithStatementTest.java: -------------------------------------------------------------------------------- 1 | package com.shapesecurity.shift.es2018.parser.statements; 2 | 3 | import com.shapesecurity.functional.data.ImmutableList; 4 | import com.shapesecurity.shift.es2018.ast.Block; 5 | import com.shapesecurity.shift.es2018.ast.BlockStatement; 6 | import com.shapesecurity.shift.es2018.ast.EmptyStatement; 7 | import com.shapesecurity.shift.es2018.ast.ExpressionStatement; 8 | import com.shapesecurity.shift.es2018.ast.IdentifierExpression; 9 | import com.shapesecurity.shift.es2018.ast.LiteralNumericExpression; 10 | import com.shapesecurity.shift.es2018.ast.WithStatement; 11 | import com.shapesecurity.shift.es2018.parser.ParserTestCase; 12 | import com.shapesecurity.shift.es2018.parser.JsError; 13 | 14 | import org.junit.Test; 15 | 16 | public class WithStatementTest extends ParserTestCase { 17 | @Test 18 | public void testWithStatement() throws JsError { 19 | testScript("with(1);", new WithStatement(new LiteralNumericExpression(1.0), new EmptyStatement())); 20 | 21 | testScript("with (x) foo", new WithStatement(new IdentifierExpression("x"), new ExpressionStatement( 22 | new IdentifierExpression("foo") 23 | ))); 24 | 25 | testScript("with (x) foo", new WithStatement(new IdentifierExpression("x"), new ExpressionStatement( 26 | new IdentifierExpression("foo") 27 | ))); 28 | 29 | testScript("with (x) { foo }", new WithStatement(new IdentifierExpression("x"), new BlockStatement( 30 | new Block(ImmutableList.of(new ExpressionStatement(new IdentifierExpression("foo")))) 31 | ))); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/com/shapesecurity/shift/es2018/path/BranchGetterTest.java: -------------------------------------------------------------------------------- 1 | package com.shapesecurity.shift.es2018.path; 2 | 3 | import com.shapesecurity.shift.es2018.ast.*; 4 | import com.shapesecurity.shift.es2018.parser.JsError; 5 | import com.shapesecurity.shift.es2018.parser.Parser; 6 | import junit.framework.TestCase; 7 | 8 | public class BranchGetterTest extends TestCase { 9 | public void testSimple() throws JsError { 10 | String src = "foo + bar('a', 'b');"; 11 | Script tree = Parser.parseScript(src); 12 | 13 | ExpressionStatement statement = (ExpressionStatement) tree.statements.index(0).fromJust(); 14 | BinaryExpression plus = (BinaryExpression) statement.expression; 15 | CallExpression call = (CallExpression) plus.right; 16 | LiteralStringExpression bNode = (LiteralStringExpression) call.arguments.index(1).fromJust(); 17 | 18 | BranchGetter getter = new BranchGetter() 19 | .d(Branch.ScriptStatements_(0)) 20 | .d(Branch.ExpressionStatementExpression_()) 21 | .d(Branch.BinaryExpressionRight_()) 22 | .d(Branch.CallExpressionArguments_(1)); 23 | 24 | BranchGetter getter2 = BranchGetter.of( 25 | Branch.ScriptStatements_(0), 26 | Branch.ExpressionStatementExpression_(), 27 | Branch.BinaryExpressionRight_(), 28 | Branch.CallExpressionArguments_(1) 29 | ); 30 | 31 | assertTrue(bNode == getter.apply(tree).fromJust()); 32 | assertTrue(bNode == getter2.apply(tree).fromJust()); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/com/shapesecurity/shift/es2018/path/EqualityTest.java: -------------------------------------------------------------------------------- 1 | package com.shapesecurity.shift.es2018.path; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.assertEquals; 6 | import static org.junit.Assert.assertNotEquals; 7 | 8 | public class EqualityTest { 9 | @Test 10 | public void testBranch() { 11 | assertEquals(Branch.ClassExpressionName_(), Branch.ClassExpressionName_()); 12 | assertNotEquals(Branch.ClassExpressionName_(), Branch.ClassExpressionSuper_()); 13 | 14 | assertEquals(Branch.ClassExpressionElements_(0), Branch.ClassExpressionElements_(0)); 15 | assertNotEquals(Branch.ClassExpressionElements_(0), Branch.ClassExpressionElements_(1)); 16 | } 17 | 18 | @Test 19 | public void testBranchGetter() { 20 | assertEquals(new BranchGetter(), new BranchGetter()); 21 | assertEquals(new BranchGetter().d(Branch.ClassExpressionName_()), new BranchGetter().d(Branch.ClassExpressionName_())); 22 | assertNotEquals(new BranchGetter().d(Branch.ClassExpressionName_()), new BranchGetter().d(Branch.ClassExpressionSuper_())); 23 | assertNotEquals(new BranchGetter().d(Branch.ClassExpressionName_()), new BranchGetter().d(Branch.ClassExpressionName_()).d(Branch.ClassExpressionSuper_())); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/com/shapesecurity/shift/es2018/path/ToStringTest.java: -------------------------------------------------------------------------------- 1 | package com.shapesecurity.shift.es2018.path; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.assertEquals; 6 | 7 | public class ToStringTest { 8 | @Test 9 | public void testToString() { 10 | assertEquals("", new BranchGetter().toString()); 11 | 12 | assertEquals(".statements[5].body", new BranchGetter().d(Branch.ScriptStatements_(5)).d(Branch.ForStatementBody_()).toString()); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/test/java/com/shapesecurity/shift/es2018/reducer/CloneReducerTestCase.java: -------------------------------------------------------------------------------- 1 | package com.shapesecurity.shift.es2018.reducer; 2 | 3 | import com.shapesecurity.shift.es2018.ast.Module; 4 | import com.shapesecurity.shift.es2018.ast.Script; 5 | import com.shapesecurity.shift.es2018.parser.JsError; 6 | import com.shapesecurity.shift.es2018.parser.Parser; 7 | 8 | import static org.junit.Assert.assertEquals; 9 | 10 | public abstract class CloneReducerTestCase { 11 | protected static void cloneTestScript(String sourceText) throws JsError { 12 | Script script = Parser.parseScript(sourceText); 13 | Script clone = (Script) Director.reduceScript(new ReconstructingReducer(), script); 14 | assertEquals(script, clone); 15 | 16 | // TODO: same thing, but with location this time 17 | } 18 | 19 | protected static void cloneTestModule(String sourceText) throws JsError { 20 | Module module = Parser.parseModule(sourceText); 21 | Module clone = (Module) Director.reduceModule(new ReconstructingReducer(), module); 22 | assertEquals(module, clone); 23 | 24 | // TODO: same thing, but with location this time 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/com/shapesecurity/shift/es2018/reducer/Counter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Shape Security, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.shapesecurity.shift.es2018.reducer; 18 | 19 | import com.shapesecurity.functional.data.Monoid; 20 | import com.shapesecurity.shift.es2018.ast.IdentifierExpression; 21 | 22 | import javax.annotation.Nonnull; 23 | 24 | /** 25 | * This class is an example of using reducing. To make a counter of certain leaf type of element, 26 | * simply return 1 in the corresponding reduce method. 27 | */ 28 | public class Counter extends MonoidalReducer { 29 | public Counter() { 30 | super(Monoid.INTEGER_ADDITIVE); 31 | } 32 | 33 | public static class IdentifierCounter extends Counter { 34 | @Nonnull 35 | @Override 36 | public Integer reduceIdentifierExpression(@Nonnull IdentifierExpression node) { 37 | return 1; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/com/shapesecurity/shift/es2018/reducer/VisitorTestCase.java: -------------------------------------------------------------------------------- 1 | package com.shapesecurity.shift.es2018.reducer; 2 | 3 | import junit.framework.TestCase; 4 | 5 | import javax.annotation.Nonnull; 6 | 7 | import java.io.IOException; 8 | import java.nio.ByteBuffer; 9 | import java.nio.charset.StandardCharsets; 10 | import java.nio.file.Files; 11 | import java.nio.file.Path; 12 | import java.nio.file.Paths; 13 | 14 | public abstract class VisitorTestCase extends TestCase { 15 | private static final String BASE_PATH = System.getenv("CONFIG_DIR") == null ? "src/test/resources" : System.getenv("CONFIG_DIR"); 16 | 17 | protected static Path getPath(String path) { 18 | Path pathObj = Paths.get(BASE_PATH + '/' + path); 19 | if (Files.exists(pathObj)) { 20 | return pathObj; 21 | } else { 22 | return Paths.get(path); 23 | } 24 | } 25 | 26 | @Nonnull 27 | protected static String readFile(@Nonnull String path) throws IOException { 28 | byte[] encoded = Files.readAllBytes(getPath(path)); 29 | return StandardCharsets.UTF_8.decode(ByteBuffer.wrap(encoded)).toString(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/com/shapesecurity/shift/es2018/test262/Test262Info.java: -------------------------------------------------------------------------------- 1 | package com.shapesecurity.shift.es2018.test262; 2 | 3 | import com.shapesecurity.functional.data.ImmutableSet; 4 | 5 | import javax.annotation.Nonnull; 6 | 7 | public final class Test262Info { 8 | 9 | public enum Test262Negative { 10 | PARSE, EARLY, RUNTIME, RESOLUTION, NONE 11 | } 12 | 13 | @Nonnull 14 | public final String name; 15 | @Nonnull 16 | public final Test262Negative negative; 17 | public final boolean noStrict; 18 | public final boolean onlyStrict; 19 | public final boolean async; 20 | public final boolean module; 21 | @Nonnull 22 | public final ImmutableSet features; 23 | 24 | Test262Info(@Nonnull String name, @Nonnull Test262Negative negative, boolean noStrict, boolean onlyStrict, boolean async, boolean module, @Nonnull ImmutableSet features) { 25 | this.name = name; 26 | this.negative = negative; 27 | this.noStrict = noStrict; 28 | this.onlyStrict = onlyStrict; 29 | this.async = async; 30 | this.module = module; 31 | this.features = features; 32 | } 33 | } -------------------------------------------------------------------------------- /src/test/java/com/shapesecurity/shift/es2018/test262/parser/XFailHelper.java: -------------------------------------------------------------------------------- 1 | package com.shapesecurity.shift.es2018.test262.parser; 2 | 3 | import org.junit.Test; 4 | 5 | import java.io.File; 6 | import java.util.Set; 7 | 8 | import static org.junit.Assert.assertTrue; 9 | 10 | public class XFailHelper { 11 | public static void wrap(String name, Set xfail, TestCase test) throws Exception { 12 | boolean passed = false; 13 | try { 14 | test.test(name); 15 | passed = true; 16 | } catch (Exception e) { 17 | if (!xfail.contains(name)) { 18 | throw e; 19 | } // else swallow the exception and thus pass 20 | } 21 | if (passed && xfail.contains(name)) { 22 | throw new RuntimeException("Test marked as xfail, but passed"); 23 | } 24 | } 25 | 26 | @FunctionalInterface 27 | public interface TestCase { 28 | void test(String name) throws Exception; // We need our own interface so it can throw 29 | } 30 | 31 | @Test 32 | public void ensureTestsExist() { 33 | for (String f : PassTest.xfail) { 34 | assertTrue((new File(PassTest.testsDir, f)).exists()); 35 | } 36 | 37 | for (String f : EarlyTest.xfail) { 38 | assertTrue((new File(EarlyTest.testsDir, f)).exists()); 39 | } 40 | 41 | for (String f : FailTest.xfail) { 42 | assertTrue((new File(FailTest.testsDir, f)).exists()); 43 | } 44 | } 45 | 46 | } 47 | --------------------------------------------------------------------------------