@ibyar/expressions 0.4.1 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +96 -1
- package/api/abstract.d.ts +2 -1
- package/api/abstract.js +4 -0
- package/api/abstract.js.map +1 -1
- package/api/definition/array.d.ts +3 -1
- package/api/definition/array.js +6 -0
- package/api/definition/array.js.map +1 -1
- package/api/definition/bind.d.ts +2 -1
- package/api/definition/bind.js +4 -0
- package/api/definition/bind.js.map +1 -1
- package/api/definition/function.d.ts +6 -1
- package/api/definition/function.js +22 -2
- package/api/definition/function.js.map +1 -1
- package/api/definition/member.d.ts +2 -1
- package/api/definition/member.js +4 -0
- package/api/definition/member.js.map +1 -1
- package/api/definition/object.d.ts +4 -1
- package/api/definition/object.js +10 -0
- package/api/definition/object.js.map +1 -1
- package/api/definition/statement.d.ts +2 -1
- package/api/definition/statement.js +3 -0
- package/api/definition/statement.js.map +1 -1
- package/api/definition/values.d.ts +11 -4
- package/api/definition/values.js +16 -0
- package/api/definition/values.js.map +1 -1
- package/api/deserialize/deserialize.js +3 -3
- package/api/deserialize/deserialize.js.map +1 -1
- package/api/deserialize/type-store.d.ts +2 -0
- package/api/deserialize/type-store.js +2 -0
- package/api/deserialize/type-store.js.map +1 -0
- package/api/expression.d.ts +9 -3
- package/api/expression.js.map +1 -1
- package/api/module/export.d.ts +3 -1
- package/api/module/export.js +10 -0
- package/api/module/export.js.map +1 -1
- package/api/module/import.d.ts +3 -1
- package/api/module/import.js +10 -0
- package/api/module/import.js.map +1 -1
- package/api/module/module.d.ts +2 -1
- package/api/module/module.js +5 -0
- package/api/module/module.js.map +1 -1
- package/api/operators/assignment.d.ts +2 -1
- package/api/operators/assignment.js +4 -0
- package/api/operators/assignment.js.map +1 -1
- package/api/operators/await.d.ts +2 -1
- package/api/operators/await.js +3 -0
- package/api/operators/await.js.map +1 -1
- package/api/operators/binary.d.ts +2 -1
- package/api/operators/binary.js +4 -0
- package/api/operators/binary.js.map +1 -1
- package/api/operators/chaining.d.ts +2 -1
- package/api/operators/chaining.js +3 -0
- package/api/operators/chaining.js.map +1 -1
- package/api/operators/comma.d.ts +2 -1
- package/api/operators/comma.js +3 -0
- package/api/operators/comma.js.map +1 -1
- package/api/operators/grouping.d.ts +2 -1
- package/api/operators/grouping.js +3 -0
- package/api/operators/grouping.js.map +1 -1
- package/api/operators/logical.d.ts +2 -1
- package/api/operators/logical.js +4 -0
- package/api/operators/logical.js.map +1 -1
- package/api/operators/pipeline.d.ts +2 -1
- package/api/operators/pipeline.js +5 -0
- package/api/operators/pipeline.js.map +1 -1
- package/api/operators/ternary.d.ts +2 -1
- package/api/operators/ternary.js +5 -0
- package/api/operators/ternary.js.map +1 -1
- package/api/operators/unary.d.ts +2 -1
- package/api/operators/unary.js +3 -0
- package/api/operators/unary.js.map +1 -1
- package/api/operators/update.d.ts +2 -1
- package/api/operators/update.js +3 -0
- package/api/operators/update.js.map +1 -1
- package/api/statement/control/block.d.ts +2 -1
- package/api/statement/control/block.js +3 -0
- package/api/statement/control/block.js.map +1 -1
- package/api/statement/control/if.d.ts +2 -1
- package/api/statement/control/if.js +5 -0
- package/api/statement/control/if.js.map +1 -1
- package/api/statement/control/switch.d.ts +4 -1
- package/api/statement/control/switch.js +11 -0
- package/api/statement/control/switch.js.map +1 -1
- package/api/statement/control/terminate.d.ts +5 -3
- package/api/statement/control/terminate.js +6 -0
- package/api/statement/control/terminate.js.map +1 -1
- package/api/statement/declarations/declares.d.ts +4 -1
- package/api/statement/declarations/declares.js +11 -1
- package/api/statement/declarations/declares.js.map +1 -1
- package/api/statement/iterations/for.d.ts +5 -1
- package/api/statement/iterations/for.js +21 -0
- package/api/statement/iterations/for.js.map +1 -1
- package/api/statement/iterations/while.d.ts +3 -1
- package/api/statement/iterations/while.js +8 -0
- package/api/statement/iterations/while.js.map +1 -1
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/index.js.map +1 -1
- package/package.json +3 -3
- package/scope/event.d.ts +5 -0
- package/scope/event.js +35 -0
- package/scope/event.js.map +1 -0
- package/scope/index.d.ts +1 -0
- package/scope/index.js +1 -0
- package/scope/index.js.map +1 -1
- package/scope/proxy.d.ts +1 -1
- package/scope/proxy.js +3 -3
- package/scope/proxy.js.map +1 -1
- package/scope/scope.d.ts +84 -48
- package/scope/scope.js +168 -29
- package/scope/scope.js.map +1 -1
- package/scope/stack.d.ts +28 -28
- package/scope/stack.js.map +1 -1
- package/v8/app.js.map +1 -1
- package/v8/parser.d.ts +2 -2
- package/v8/parser.js +4 -2
- package/v8/parser.js.map +1 -1
- package/v8/stream.d.ts +4 -2
- package/v8/stream.js +34 -17
- package/v8/stream.js.map +1 -1
- package/v8/token.d.ts +1 -1
- package/v8/token.js.map +1 -1
- package/visit/index.d.ts +1 -0
- package/visit/index.js +2 -0
- package/visit/index.js.map +1 -0
- package/visit/visitor.d.ts +11 -0
- package/visit/visitor.js +42 -0
- package/visit/visitor.js.map +1 -0
package/v8/app.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.js","sourceRoot":"","sources":["../../../src/expressions/v8/app.ts"],"names":[],"mappings":"","sourcesContent":["// import type { ExpressionNode } from '../api/expression.js';\n// import {\n// \tAssignmentNode, ConstNode, FunctionType,\n// \tLetNode, NullNode, StringNode, Variable\n// } from '../api/index.js';\n// import { JavaScriptParser, PropertyKind } from './parser.js';\n// import { Token } from './token.js';\n// import { MetaProperty } from '../api/app/class.js';\n\n\n// export type ClassInfo = {\n// \tisAnonymous: boolean;\n// \textends: ExpressionNode;\n// \thasSeenConstructor: boolean;\n// \thasStaticComputedNames: boolean;\n// \trequiresBrand: boolean;\n// \thasPrivateMethods: boolean,\n// \thasStaticPrivateMethods: boolean;\n// \tcomputedFieldCount: number;\n// \thasStaticElements: boolean;\n// };\n\n// export enum FunctionNameValidity {\n// \tFunctionNameIsStrictReserved = 'FunctionNameIsStrictReserved',\n// \tSkipFunctionNameCheck = 'SkipFunctionNameCheck',\n// \tFunctionNameValidityUnknown = 'FunctionNameValidityUnknown'\n// };\n\n// export enum AllowLabelledFunctionStatement {\n// \tAllowLabelledFunctionStatement = 'AllowLabelledFunctionStatement',\n// \tDisallowLabelledFunctionStatement = 'DisallowLabelledFunctionStatement',\n// };\n\n// export enum ParsingArrowHeadFlag {\n// \tCertainlyNotArrowHead = 'CertainlyNotArrowHead',\n// \tMaybeArrowHead = 'MaybeArrowHead'\n// };\n\n// export enum PropertyPosition {\n// \tObjectLiteral = 'ObjectLiteral',\n// \tClassLiteral = 'ClassLiteral'\n// }\n\n// const FUNCTIONS_TYPES: FunctionType[][][] = [\n// \t[\n// \t\t// SubFunctionKind::kNormalFunction\n// \t\t[// is_generator=false\n// \t\t\tFunctionType.NORMAL,\n// \t\t\tFunctionType.ASYNC\n// \t\t],\n// \t\t[// is_generator=true\n// \t\t\tFunctionType.GENERATOR,\n// \t\t\tFunctionType.ASYNC_GENERATOR\n// \t\t],\n// \t],\n// \t[\n// \t\t// SubFunctionKind::kNonStaticMethod\n// \t\t[// is_generator=false\n// \t\t\tFunctionType.CONCISE,\n// \t\t\tFunctionType.ASYNC_CONCISE\n// \t\t],\n// \t\t[// is_generator=true\n// \t\t\tFunctionType.CONCISE_GENERATOR,\n// \t\t\tFunctionType.ASYNC_CONCISE_GENERATOR\n// \t\t],\n// \t],\n// \t[\n// \t\t// SubFunctionKind::kStaticMethod\n// \t\t[// is_generator=false\n// \t\t\tFunctionType.STATIC_CONCISE,\n// \t\t\tFunctionType.STATIC_ASYNC_CONCISE\n// \t\t],\n// \t\t[// is_generator=true\n// \t\t\tFunctionType.STATIC_CONCISE_GENERATOR,\n// \t\t\tFunctionType.STATIC_ASYNC_CONCISE_GENERATOR\n// \t\t],\n// \t]\n// ];\n\n// export enum SubFunctionKind {\n// \tNormalFunction,\n// \tNonStaticMethod,\n// \tStaticMethod,\n// }\n\n// export function functionKindForImpl(subFunctionKind: SubFunctionKind, isGenerator: boolean, isAsync: boolean): FunctionType {\n// \treturn FUNCTIONS_TYPES[subFunctionKind as number][isGenerator ? 1 : 0][isAsync ? 1 : 0];\n// }\n\n// export class ParsePropertyInfo {\n// \tname: ExpressionNode;\n// \tposition = PropertyPosition.ClassLiteral;\n// \tfunctionFlags = FunctionType.NORMAL;\n// \tkind = PropertyKind.NotSet;\n// \tisComputedName = false;\n// \tisPrivate = false;\n// \tisStatic = false;\n// \tisRest = false;\n\n// \tPropertyKindFromToken(token: Token): boolean {\n// \t\t// This returns true, setting the property kind, iff the given token is\n// \t\t// one which must occur after a property name, indicating that the\n// \t\t// previous token was in fact a name and not a modifier (like the \"get\" in\n// \t\t// \"get x\").\n// \t\tswitch (token) {\n// \t\t\tcase Token.COLON:\n// \t\t\t\tthis.kind = PropertyKind.Value;\n// \t\t\t\treturn true;\n// \t\t\tcase Token.COMMA:\n// \t\t\t\tthis.kind = PropertyKind.Shorthand;\n// \t\t\t\treturn true;\n// \t\t\tcase Token.R_CURLY:\n// \t\t\t\tthis.kind = PropertyKind.ShorthandOrClassField;\n// \t\t\t\treturn true;\n// \t\t\tcase Token.ASSIGN:\n// \t\t\t\tthis.kind = PropertyKind.Assign;\n// \t\t\t\treturn true;\n// \t\t\tcase Token.L_PARENTHESES:\n// \t\t\t\tthis.kind = PropertyKind.Method;\n// \t\t\t\treturn true;\n// \t\t\tcase Token.MUL:\n// \t\t\tcase Token.SEMICOLON:\n// \t\t\t\tthis.kind = PropertyKind.ClassField;\n// \t\t\t\treturn true;\n// \t\t\tdefault:\n// \t\t\t\tbreak;\n// \t\t}\n// \t\treturn false;\n// \t}\n\n// }\n// enum ObjectLiteralPropertyKind {\n// \tCONSTANT = 'CONSTANT',\t// Property with constant value (compile time).\n// \tCOMPUTED = 'COMPUTED',\t// Property with computed value (execution time).\n// \tMATERIALIZED_LITERAL = 'MATERIALIZED_LITERAL', // Property value is a materialized literal.\n// \tGETTER = 'GETTER',\n// \tSETTER = 'SETTER',\t\t// Property is an accessor function.\n// \tPROTOTYPE = 'PROTOTYPE',\t// Property is __proto__.\n// \tSPREAD = 'SPREAD'\n// }\n// export class ObjectLiteralProperty {\n// \tstatic Kind = ObjectLiteralPropertyKind;\n// }\n\n// enum ClassLiteralPropertyKind {\n// \tMETHOD = 'METHOD',\n// \tGETTER = 'GETTER',\n// \tSETTER = 'SETTER',\n// \tFIELD = 'FIELD'\n// }\n\n// export class ClassLiteralProperty {\n// \tstatic Kind = ClassLiteralPropertyKind;\n// }\n\n// function assertUnreachable(x: never): never {\n// \tthrow new Error(`Didn't expect to get here`);\n// }\n// export function classPropertyKindFor(kind: PropertyKind): ClassLiteralPropertyKind {\n// \tswitch (kind) {\n// \t\tcase PropertyKind.AccessorGetter:\n// \t\t\treturn ClassLiteralPropertyKind.GETTER;\n// \t\tcase PropertyKind.AccessorSetter:\n// \t\t\treturn ClassLiteralPropertyKind.SETTER;\n// \t\tcase PropertyKind.Method:\n// \t\t\treturn ClassLiteralPropertyKind.METHOD;\n// \t\tcase PropertyKind.ClassField:\n// \t\t\treturn ClassLiteralPropertyKind.FIELD;\n// \t}\n// \tthrow new Error(`unexpected property kind: ${kind}`);\n// }\n\n// export enum VariableMode {\n// \tConst = 'Const',\n// \tPrivateMethod = 'PrivateMethod',\n// \tPrivateGetterOnly = 'PrivateGetterOnly',\n// \tPrivateSetterOnly = 'PrivateSetterOnly'\n// }\n\n// export function getVariableMode(kind: ClassLiteralPropertyKind): VariableMode {\n// \tswitch (kind) {\n// \t\tcase ClassLiteralPropertyKind.FIELD:\n// \t\t\treturn VariableMode.Const;\n// \t\tcase ClassLiteralPropertyKind.METHOD:\n// \t\t\treturn VariableMode.PrivateMethod;\n// \t\tcase ClassLiteralPropertyKind.GETTER:\n// \t\t\treturn VariableMode.PrivateGetterOnly;\n// \t\tcase ClassLiteralPropertyKind.SETTER:\n// \t\t\treturn VariableMode.PrivateSetterOnly;\n// \t}\n// }\n\n// export class JavaScriptAppParser extends JavaScriptParser {\n// \tprotected parseNewTargetExpression(): ExpressionNode {\n// \t\tthis.consume(Token.PERIOD);\n//\t\t const target: ExpressionNode = this.parsePropertyName();\n//\t\t if (target.toString() !== 'target') {\n//\t\t \tthrow new Error(this.errorMessage(`Expression (new.${target.toString()}) not supported.`));\n//\t\t }\n//\t\t return MetaProperty.NewTarget;\n// \t}\n// \tprotected parseClassDeclaration(names: ExpressionNode[] | undefined, defaultExport: boolean): ExpressionNode {\n// \t\t// ClassDeclaration ::\n// \t\t// 'class' Identifier ('extends' LeftHandExpression)? '{' ClassBody '}'\n// \t\t// 'class' ('extends' LeftHandExpression)? '{' ClassBody '}'\n// \t\t//\n// \t\t// The anonymous form is allowed iff [default_export] is true.\n// \t\t//\n// \t\t// 'class' is expected to be consumed by the caller.\n// \t\t//\n// \t\t// A ClassDeclaration\n// \t\t//\n// \t\t// class C { ... }\n// \t\t//\n// \t\t// has the same semantics as:\n// \t\t//\n// \t\t// let C = class C { ... };\n// \t\t//\n// \t\t// so rewrite it as such.\n\n// \t\tconst nextToken = this.peek().token;\n// \t\tconst isStrictReserved = Token.isStrictReservedWord(nextToken);\n// \t\tlet name: ExpressionNode | undefined;\n// \t\tlet variableName: ExpressionNode | undefined;\n// \t\tif (defaultExport && (nextToken == Token.EXTENDS || nextToken == Token.L_CURLY)) {\n// \t\t\tname = new StringNode('default');\n// \t\t\tvariableName = new StringNode('.default');\n// \t\t} else {\n// \t\t\tname = this.parseIdentifier();\n// \t\t\tvariableName = name;\n// \t\t}\n// \t\tconst value = this.parseClassLiteral(name, isStrictReserved);\n// \t\treturn this.declareClass(variableName, value, names);\n// \t}\n// \tprotected parseClassLiteral(name: ExpressionNode | undefined, nameIsStrictReserved: boolean): ExpressionNode {\n// \t\t// throw new Error(this.errorMessage(`Expression (class) not supported.`));\n// \t\tconst isAnonymous = !!!name;\n\n// \t\t// All parts of a ClassDeclaration and ClassExpression are strict code.\n// \t\tif (!isAnonymous) {\n// \t\t\tif (nameIsStrictReserved) {\n// \t\t\t\tthrow new Error(this.errorMessage(`Unexpected Strict Reserved class name`));\n// \t\t\t}\n// \t\t\tif (this.isEvalOrArguments(name!)) {\n// \t\t\t\tthrow new Error(this.errorMessage(`Strict Eval Arguments not allowed for class name`));\n// \t\t\t}\n// \t\t}\n\n// \t\t// ClassScope * class_scope = NewClassScope(scope(), is_anonymous);\n// \t\t// BlockState block_state(& scope_, class_scope);\n// \t\t// RaiseLanguageMode(LanguageMode.kStrict);\n\n// \t\t// BlockState object_literal_scope_state(& object_literal_scope_, nullptr);\n\n// \t\t// ClassInfo classInfo(this);\n// \t\t// classInfo.is_anonymous = is_anonymous;\n\n// \t\tconst classInfo = { isAnonymous, computedFieldCount: 0 } as ClassInfo;\n\n// \t\t// scope() -> set_start_position(class_token_pos);\n// \t\tif (this.check(Token.EXTENDS)) {\n// \t\t\t// ClassScope.HeritageParsingScope heritage(class_scope);\n// \t\t\t// FuncNameInferrerState fni_state(& fni_);\n// \t\t\t// ExpressionParsingScope scope(impl());\n// \t\t\tclassInfo.extends = this.parseLeftHandSideExpression();\n// \t\t\t// scope.ValidateExpression();\n// \t\t}\n\n// \t\tthis.expect(Token.L_CURLY);\n\n// \t\tconst hasExtends = !(classInfo.extends === undefined);\n\n// \t\tconst staticBlockList: ExpressionNode[] = [];\n// \t\tconst privateClassMemberList: ExpressionNode[] = [];\n// \t\tconst publicClassFieldList: ExpressionNode[] = [];\n// \t\tconst publicClassMethodList: ExpressionNode[] = [];\n\n// \t\twhile (this.peek().isNotType(Token.R_CURLY)) {\n// \t\t\tif (this.check(Token.SEMICOLON)) continue;\n\n// \t\t\t// Either we're parsing a `static { }` initialization block or a property.\n// \t\t\tif (this.peek().isType(Token.STATIC) && this.peekAhead().isType(Token.L_CURLY)) {\n// \t\t\t\tconst staticBlock = this.parseClassStaticBlock(classInfo);\n// \t\t\t\tstaticBlockList.push(staticBlock);\n// \t\t\t\tcontinue;\n// \t\t\t}\n\n// \t\t\t// FuncNameInferrerState fni_state(& fni_);\n// \t\t\t// If we haven't seen the constructor yet, it potentially is the next\n// \t\t\t// property.\n// \t\t\tlet isConstructor = !classInfo.hasSeenConstructor;\n// \t\t\tconst propInfo = new ParsePropertyInfo();\n// \t\t\tpropInfo.position = PropertyPosition.ClassLiteral;\n\n// \t\t\tconst property = this.parseClassPropertyDefinition(classInfo, propInfo, hasExtends);\n\n// \t\t\t// if (has_error()) return impl() -> FailureExpression();\n\n// \t\t\tconst propertyKind = classPropertyKindFor(propInfo.kind);\n// \t\t\tif (!classInfo.hasStaticComputedNames && propInfo.isStatic && propInfo.isComputedName) {\n// \t\t\t\tclassInfo.hasStaticComputedNames = true;\n// \t\t\t}\n// \t\t\tisConstructor &&= classInfo.hasSeenConstructor;\n\n// \t\t\tconst isField = propertyKind == ClassLiteralPropertyKind.FIELD;\n\n// \t\t\tif (propInfo.isPrivate) {\n// \t\t\t\tif (isConstructor) {\n// \t\t\t\t\tthrow new Error(this.errorMessage('private constructor is not allowed'));\n// \t\t\t\t}\n// \t\t\t\tclassInfo.requiresBrand ||= (!isField && !propInfo.isStatic);\n// \t\t\t\tconst isMethod = propertyKind == ClassLiteralPropertyKind.METHOD;\n// \t\t\t\tclassInfo.hasPrivateMethods ||= isMethod;\n// \t\t\t\tclassInfo.hasStaticPrivateMethods ||= isMethod && propInfo.isStatic;\n// \t\t\t\tconst privateClassMember = this.declarePrivateClassMember(propInfo.name, property, propertyKind, propInfo.isStatic, classInfo);\n// \t\t\t\tprivateClassMemberList.push(privateClassMember);\n// \t\t\t\tcontinue;\n// \t\t\t}\n\n// \t\t\tif (isField) {\n// \t\t\t\tif (propInfo.isComputedName) {\n// \t\t\t\t\tclassInfo.computedFieldCount++;\n// \t\t\t\t}\n// \t\t\t\tconst publicClassField = this.declarePublicClassField(property, propInfo.isStatic, propInfo.isComputedName, classInfo);\n// \t\t\t\tpublicClassFieldList.push(publicClassField);\n// \t\t\t\tcontinue;\n// \t\t\t}\n\n// \t\t\tconst publicClassMethod = this.declarePublicClassMethod(name, property, isConstructor, classInfo);\n// \t\t\tpublicClassMethodList.push(publicClassMethod);\n// \t\t}\n\n// \t\tthis.expect(Token.R_CURLY);\n// \t\t// int end_pos = end_position();\n// \t\t// class_scope -> set_end_position(end_pos);\n\n// \t\t// VariableProxy * unresolvable = class_scope -> ResolvePrivateNamesPartially();\n// \t\t// if (unresolvable != nullptr) {\n// \t\t// \timpl() -> ReportMessageAt(Scanner.Location(unresolvable -> position(),unresolvable -> position() + 1),\n// \t\t// \t\tMessageTemplate.kInvalidPrivateFieldResolution,\n// \t\t// \t\tunresolvable -> raw_name());\n// \t\t// \treturn impl() -> FailureExpression();\n// \t\t// }\n\n// \t\t// if (classInfo.requiresBrand) {\n// \t\t// \tclass_scope -> DeclareBrandVariable(ast_value_factory(), IsStaticFlag.kNotStatic, kNoSourcePosition);\n// \t\t// }\n\n// \t\t// if (class_scope -> needs_home_object()) {\n// \t\t// \tclassInfo.homeObjectVariable = class_scope -> DeclareHomeObjectVariable(ast_value_factory());\n// \t\t// \tclassInfo.staticHomeObjectVariable = class_scope -> DeclareStaticHomeObjectVariable(ast_value_factory());\n// \t\t// }\n\n// \t\t// bool should_save_class_variable_index = class_scope -> should_save_class_variable_index();\n// \t\t// if (!isAnonymous || should_save_class_variable_index) {\n// \t\t// \tthis.declareClassVariable(name, classInfo);\n// \t\t// \tif (should_save_class_variable_index) {\n// \t\t// \t\tclass_scope -> class_variable() -> set_is_used();\n// \t\t// \t\tclass_scope -> class_variable() -> ForceContextAllocation();\n// \t\t// \t}\n// \t\t// }\n// \t\treturn this.rewriteClassLiteral(name, classInfo);\n// \t}\n// \tprotected declarePublicClassMethod(name: ExpressionNode | undefined, property: ExpressionNode, isConstructor: boolean, classInfo: ClassInfo): ExpressionNode {\n// \t\tthrow new Error('Method not implemented.');\n// \t}\n// \tprotected declarePublicClassField(property: ExpressionNode, isStatic: boolean, isComputedName: boolean, classInfo: ClassInfo): ExpressionNode {\n// \t\tthrow new Error('Method not implemented.');\n// \t}\n// \tprotected inferFunctionName() {\n// \t\tthrow new Error('Method not implemented.');\n// \t}\n// \tprotected declarePrivateClassMember(name: ExpressionNode, property: ExpressionNode, propertyKind: ClassLiteralPropertyKind, isStatic: boolean, classInfo: ClassInfo): ExpressionNode {\n// \t\tthrow new Error('Method not implemented.');\n// \t}\n// \tprotected parseClassPropertyDefinition(classInfo: ClassInfo, propInfo: ParsePropertyInfo, hasExtends: boolean): ExpressionNode {\n// \t\tif (!classInfo) {\n// \t\t\tthrow new Error(this.errorMessage('class info is undefined'));\n// \t\t}\n// \t\tif (propInfo.position !== PropertyPosition.ClassLiteral) {\n// \t\t\tthrow new Error(this.errorMessage('expected property position ClassLiteral'));\n// \t\t}\n\n// \t\tconst nameToken = this.peek();\n// \t\tlet nameExpression: ExpressionNode;\n// \t\tif (nameToken.isType(Token.STATIC)) {\n// \t\t\tthis.consume(Token.STATIC);\n// \t\t\tif (this.peek().isType(Token.L_PARENTHESES)) {\n// \t\t\t\tpropInfo.kind = PropertyKind.Method;\n// \t\t\t\tpropInfo.name = this.parseIdentifier()!;\n// \t\t\t\tnameExpression = new StringNode(propInfo.name.toString());\n// \t\t\t} else if (this.peek().isType(Token.ASSIGN)\n// \t\t\t\t|| this.peek().isType(Token.SEMICOLON)\n// \t\t\t\t|| this.peek().isType(Token.R_BRACKETS)) {\n// \t\t\t\tpropInfo.name = this.parseIdentifier()!;\n// \t\t\t\tnameExpression = new StringNode(propInfo.name.toString());\n// \t\t\t} else {\n// \t\t\t\tpropInfo.isStatic = true;\n// \t\t\t\tnameExpression = this.parseProperty(propInfo);\n// \t\t\t}\n// \t\t} else {\n// \t\t\tnameExpression = this.parseProperty(propInfo);\n// \t\t}\n\n// \t\tswitch (propInfo.kind) {\n// \t\t\tcase PropertyKind.Assign:\n// \t\t\tcase PropertyKind.ClassField:\n// \t\t\tcase PropertyKind.ShorthandOrClassField:\n// \t\t\tcase PropertyKind.NotSet: {\n// \t\t\t\t// This case is a name followed by a\n// \t\t\t\t// name or other property. Here we have\n// \t\t\t\t// to assume that's an uninitialized\n// \t\t\t\t// field followed by a line break\n// \t\t\t\t// followed by a property, with ASI\n// \t\t\t\t// adding the semicolon. If not, there\n// \t\t\t\t// will be a syntax error after parsing\n// \t\t\t\t// the first name as an uninitialized\n// \t\t\t\t// field.\n// \t\t\t\tpropInfo.kind = PropertyKind.ClassField;\n\n// \t\t\t\t// if (!propInfo.isComputedName) {\n// \t\t\t\t// \tthis.checkClassFieldName(propInfo.name, propInfo.isStatic);\n// \t\t\t\t// }\n\n// \t\t\t\tconst initializer: ExpressionNode = this.parseMemberInitializer(classInfo, propInfo.isStatic);\n// \t\t\t\tthis.expectSemicolon();\n\n// \t\t\t\tconst result: ExpressionNode = this.newClassLiteralProperty(\n// \t\t\t\t\tnameExpression,\n// \t\t\t\t\tinitializer,\n// \t\t\t\t\tClassLiteralPropertyKind.FIELD,\n// \t\t\t\t\tpropInfo.isStatic,\n// \t\t\t\t\tpropInfo.isComputedName,\n// \t\t\t\t\tpropInfo.isPrivate\n// \t\t\t\t);\n// \t\t\t\tthis.setFunctionNameFromPropertyName(result, propInfo.name);\n// \t\t\t\treturn result;\n// \t\t\t}\n// \t\t\tcase PropertyKind.Method: {\n// \t\t\t\t// MethodDefinition\n// \t\t\t\t// PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}'\n// \t\t\t\t// '*' PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}'\n// \t\t\t\t// async PropertyName '(' StrictFormalParameters ')'\n// \t\t\t\t// '{' FunctionBody '}'\n// \t\t\t\t// async '*' PropertyName '(' StrictFormalParameters ')'\n// \t\t\t\t// '{' FunctionBody '}'\n\n// \t\t\t\t// if (!propInfo.isComputedName) {\n// \t\t\t\t// \tthis.checkClassMethodName(propInfo.name, PropertyKind.Method,propInfo.functionFlags, propInfo.isStatic,classInfo . hasSeenConstructor);\n// \t\t\t\t// }\n\n// \t\t\t\tlet kind: FunctionType = this.methodKindFor(propInfo.isStatic, propInfo.functionFlags);\n\n// \t\t\t\tif (!propInfo.isStatic && propInfo.name.toString() === 'constructor') {\n// \t\t\t\t\tclassInfo.hasSeenConstructor = true;\n// \t\t\t\t\tkind = hasExtends ? FunctionType.DERIVED_CONSTRUCTOR : FunctionType.BASE_CONSTRUCTOR;\n// \t\t\t\t}\n\n// \t\t\t\tconst value = this.parseFunctionLiteral(\n// \t\t\t\t\tkind,\n// \t\t\t\t\tpropInfo.name\n// \t\t\t\t\t// ,kSkipFunctionNameCheck, kind, FunctionSyntaxKind.kAccessorOrMethod\n// \t\t\t\t);\n\n// \t\t\t\tClassLiteralPropertyT result = factory() -> NewClassLiteralProperty(\n// \t\t\t\t\tname_expression, value, ClassLiteralProperty.METHOD,\n// \t\t\t\t\tpropInfo.is_static, propInfo.is_computed_name,\n// \t\t\t\t\tpropInfo.is_private);\n// \t\t\t\timpl() -> SetFunctionNameFromPropertyName(result, propInfo.name);\n// \t\t\t\treturn result;\n// \t\t\t}\n\n// \t\t\tcase PropertyKind.AccessorGetter:\n// \t\t\tcase PropertyKind.AccessorSetter: {\n// \t\t\t\tDCHECK_EQ(propInfo.function_flags, ParseFunctionFlag.kIsNormal);\n// \t\t\t\tbool is_get = propInfo.kind == PropertyKind.kAccessorGetter;\n\n// \t\t\t\tif (!propInfo.is_computed_name) {\n// \t\t\t\t\tCheckClassMethodName(propInfo.name, propInfo.kind,\n// \t\t\t\t\t\tParseFunctionFlag.kIsNormal, propInfo.is_static,\n// & class_info -> has_seen_constructor);\n// \t\t\t\t\t// Make sure the name expression is a string since we need a Name for\n// \t\t\t\t\t// Runtime_DefineAccessorPropertyUnchecked and since we can determine\n// \t\t\t\t\t// this statically we can skip the extra runtime check.\n// \t\t\t\t\tname_expression = factory() -> NewStringLiteral(\n// \t\t\t\t\t\tpropInfo.name, name_expression -> position());\n// \t\t\t\t}\n\n// \t\t\t\tFunctionKind kind;\n// \t\t\t\tif (propInfo.is_static) {\n// \t\t\t\t\tkind = is_get ? FunctionKind.kStaticGetterFunction\n// \t\t\t\t\t\t: FunctionKind.kStaticSetterFunction;\n// \t\t\t\t} else {\n// \t\t\t\t\tkind = is_get ? FunctionKind.kGetterFunction\n// \t\t\t\t\t\t: FunctionKind.kSetterFunction;\n// \t\t\t\t}\n\n// \t\t\t\tFunctionLiteralT value = impl() -> ParseFunctionLiteral(\n// \t\t\t\t\tpropInfo.name, scanner() -> location(), kSkipFunctionNameCheck, kind,\n// \t\t\t\t\tname_token_position, FunctionSyntaxKind.kAccessorOrMethod,\n// \t\t\t\t\tlanguage_mode(), nullptr);\n\n// \t\t\t\tClassLiteralPropertyKind property_kind =\n// \t\t\t\t\tis_get ? ClassLiteralProperty.GETTER : ClassLiteralProperty.SETTER;\n// \t\t\t\tClassLiteralPropertyT result = factory() -> NewClassLiteralProperty(\n// \t\t\t\t\tname_expression, value, property_kind, propInfo.is_static,\n// \t\t\t\t\tpropInfo.is_computed_name, propInfo.is_private);\n// \t\t\t\tconst AstRawString* prefix =\n// \t\t\t\tis_get ? ast_value_factory() -> get_space_string()\n// \t\t\t\t\t: ast_value_factory() -> set_space_string();\n// \t\t\t\timpl() -> SetFunctionNameFromPropertyName(result, propInfo.name, prefix);\n// \t\t\t\treturn result;\n// \t\t\t}\n// \t\t\tcase PropertyKind.Value:\n// \t\t\tcase PropertyKind.Shorthand:\n// \t\t\tcase PropertyKind.Spread:\n// \t\t\t\t// throw new Error(this.errorMessage('Report Unexpected Token'));\n// \t\t\t\treturn NullNode;\n// \t\t}\n// \t\tthrow new Error(this.errorMessage('UNREACHABLE'));\n// \t}\n// \tprotected methodKindFor(isStatic: boolean, functionFlags: FunctionType): FunctionType {\n// \t\tconst isGenerator = functionFlags.includes('GENERATOR');\n// \t\tconst isAsync = functionFlags.includes('ASYNC');\n// \t\treturn functionKindForImpl(\n// \t\t\tisStatic ? SubFunctionKind.StaticMethod : SubFunctionKind.NonStaticMethod,\n// \t\t\tisGenerator,\n// \t\t\tisAsync\n// \t\t);\n// \t}\n// \tnewClassLiteralProperty(nameExpression: ExpressionNode, initializer: ExpressionNode, FIELD: ClassLiteralPropertyKind, isStatic: boolean, isComputedName: boolean, isPrivate: boolean): ExpressionNode {\n// \t\tthrow new Error('Method not implemented.');\n// \t}\n// \tparseMemberInitializer(classInfo: ClassInfo, isStatic: boolean): ExpressionNode {\n// \t\tthrow new Error('Method not implemented.');\n// \t}\n// \tprotected parseClassStaticBlock(classInfo: ClassInfo): ExpressionNode {\n// \t\tthis.consume(Token.STATIC);\n// \t\t// Each static block has its own var and lexical scope, so make a new var\n// \t\t// block scope instead of using the synthetic members initializer function\n// \t\t// scope.\n// \t\tconst staticBlock = this.parseBlock();\n// \t\tclassInfo.hasStaticElements = true;\n// \t\treturn staticBlock;\n\n// \t}\n// \tprotected declareClass(variableName: ExpressionNode | undefined, value: ExpressionNode, names: ExpressionNode[] | undefined): ExpressionNode {\n// \t\tif (names && variableName) {\n// \t\t\tconst proxy = this.declareVariable(variableName, 'let');\n// \t\t\tnames.push(variableName);\n// \t\t\treturn new AssignmentNode('=', proxy, value);\n// \t\t}\n// \t\treturn value;\n// \t}\n// \tprotected parseSuperExpression(): ExpressionNode {\n// \t\tthrow new Error(this.errorMessage('Expression (supper) not supported.'));\n// \t}\n// \tprotected parseImportExpressions(): ExpressionNode {\n// \t\tthrow new Error(this.errorMessage('Expression (import) not supported.'));\n// \t}\n// \tprotected declareVariable(name: ExpressionNode | undefined, mode: 'let' | 'const' | 'var') {\n// \t\tif (!name) {\n// \t\t\tthrow new Error(this.errorMessage('Variable name is undefined'));\n// \t\t}\n// \t\tswitch (mode) {\n// \t\t\tcase 'const':\n// \t\t\t\treturn new ConstNode([new Variable(name)]);\n// \t\t\tdefault:\n// \t\t\tcase 'var':\n// \t\t\tcase 'let':\n// \t\t\t\treturn new LetNode([new Variable(name)]);\n// \t\t}\n// \t}\n// }\n"]}
|
|
1
|
+
{"version":3,"file":"app.js","sourceRoot":"","sources":["../../../src/expressions/v8/app.ts"],"names":[],"mappings":"","sourcesContent":["// import type { CanDeclareExpression, ExpressionNode } from '../api/expression.js';\n// import { JavaScriptParser, PropertyKind, PropertyKindInfo } from './parser.js';\n// import { Token } from './token.js';\n// import { MetaProperty } from '../api/app/class.js';\n// import { FunctionKind } from '../api/definition/function.js';\n// import { Identifier, Literal } from '../api/definition/values.js';\n// import { AssignmentExpression } from '../api/operators/assignment.js';\n// import { VariableDeclarationNode, VariableNode } from '../api/statement/declarations/declares.js';\n\n\n// export type ClassInfo = {\n// \tisAnonymous: boolean;\n// \textends: ExpressionNode;\n// \thasSeenConstructor: boolean;\n// \thasStaticComputedNames: boolean;\n// \trequiresBrand: boolean;\n// \thasPrivateMethods: boolean,\n// \thasStaticPrivateMethods: boolean;\n// \tcomputedFieldCount: number;\n// \thasStaticElements: boolean;\n// };\n\n// export enum FunctionNameValidity {\n// \tFunctionNameIsStrictReserved = 'FunctionNameIsStrictReserved',\n// \tSkipFunctionNameCheck = 'SkipFunctionNameCheck',\n// \tFunctionNameValidityUnknown = 'FunctionNameValidityUnknown'\n// };\n\n// export enum AllowLabelledFunctionStatement {\n// \tAllowLabelledFunctionStatement = 'AllowLabelledFunctionStatement',\n// \tDisallowLabelledFunctionStatement = 'DisallowLabelledFunctionStatement',\n// };\n\n// export enum ParsingArrowHeadFlag {\n// \tCertainlyNotArrowHead = 'CertainlyNotArrowHead',\n// \tMaybeArrowHead = 'MaybeArrowHead'\n// };\n\n// export enum PropertyPosition {\n// \tObjectLiteral = 'ObjectLiteral',\n// \tClassLiteral = 'ClassLiteral'\n// }\n\n// const FUNCTIONS_TYPES: FunctionKind[][][] = [\n// \t[\n// \t\t// SubFunctionKind::kNormalFunction\n// \t\t[// is_generator=false\n// \t\t\tFunctionKind.NORMAL,\n// \t\t\tFunctionKind.ASYNC\n// \t\t],\n// \t\t[// is_generator=true\n// \t\t\tFunctionKind.GENERATOR,\n// \t\t\tFunctionKind.ASYNC_GENERATOR\n// \t\t],\n// \t],\n// \t[\n// \t\t// SubFunctionKind::kNonStaticMethod\n// \t\t[// is_generator=false\n// \t\t\tFunctionKind.CONCISE,\n// \t\t\tFunctionKind.ASYNC_CONCISE\n// \t\t],\n// \t\t[// is_generator=true\n// \t\t\tFunctionKind.CONCISE_GENERATOR,\n// \t\t\tFunctionKind.ASYNC_CONCISE_GENERATOR\n// \t\t],\n// \t],\n// \t[\n// \t\t// SubFunctionKind::kStaticMethod\n// \t\t[// is_generator=false\n// \t\t\tFunctionKind.STATIC_CONCISE,\n// \t\t\tFunctionKind.STATIC_ASYNC_CONCISE\n// \t\t],\n// \t\t[// is_generator=true\n// \t\t\tFunctionKind.STATIC_CONCISE_GENERATOR,\n// \t\t\tFunctionKind.STATIC_ASYNC_CONCISE_GENERATOR\n// \t\t],\n// \t]\n// ];\n\n// export enum SubFunctionKind {\n// \tNormalFunction,\n// \tNonStaticMethod,\n// \tStaticMethod,\n// }\n\n// export function functionKindForImpl(subFunctionKind: SubFunctionKind, isGenerator: boolean, isAsync: boolean): FunctionKind {\n// \treturn FUNCTIONS_TYPES[subFunctionKind as number][isGenerator ? 1 : 0][isAsync ? 1 : 0];\n// }\n\n// export class ParsePropertyInfo implements PropertyKindInfo {\n// \tname: string;\n// \tposition = PropertyPosition.ClassLiteral;\n// \tfuncFlag = FunctionKind.NORMAL;\n// \tkind = PropertyKind.NotSet;\n// \tisComputedName = false;\n// \tisPrivate = false;\n// \tisStatic = false;\n// \tisRest = false;\n\n// \tPropertyKindFromToken(token: Token): boolean {\n// \t\t// This returns true, setting the property kind, iff the given token is\n// \t\t// one which must occur after a property name, indicating that the\n// \t\t// previous token was in fact a name and not a modifier (like the \"get\" in\n// \t\t// \"get x\").\n// \t\tswitch (token) {\n// \t\t\tcase Token.COLON:\n// \t\t\t\tthis.kind = PropertyKind.Value;\n// \t\t\t\treturn true;\n// \t\t\tcase Token.COMMA:\n// \t\t\t\tthis.kind = PropertyKind.Shorthand;\n// \t\t\t\treturn true;\n// \t\t\tcase Token.R_CURLY:\n// \t\t\t\tthis.kind = PropertyKind.ShorthandOrClassField;\n// \t\t\t\treturn true;\n// \t\t\tcase Token.ASSIGN:\n// \t\t\t\tthis.kind = PropertyKind.Assign;\n// \t\t\t\treturn true;\n// \t\t\tcase Token.L_PARENTHESES:\n// \t\t\t\tthis.kind = PropertyKind.Method;\n// \t\t\t\treturn true;\n// \t\t\tcase Token.MUL:\n// \t\t\tcase Token.SEMICOLON:\n// \t\t\t\tthis.kind = PropertyKind.ClassField;\n// \t\t\t\treturn true;\n// \t\t\tdefault:\n// \t\t\t\tbreak;\n// \t\t}\n// \t\treturn false;\n// \t}\n\n// }\n// enum ObjectLiteralPropertyKind {\n// \tCONSTANT = 'CONSTANT',\t// Property with constant value (compile time).\n// \tCOMPUTED = 'COMPUTED',\t// Property with computed value (execution time).\n// \tMATERIALIZED_LITERAL = 'MATERIALIZED_LITERAL', // Property value is a materialized literal.\n// \tGETTER = 'GETTER',\n// \tSETTER = 'SETTER',\t\t// Property is an accessor function.\n// \tPROTOTYPE = 'PROTOTYPE',\t// Property is __proto__.\n// \tSPREAD = 'SPREAD'\n// }\n// export class ObjectLiteralProperty {\n// \tstatic Kind = ObjectLiteralPropertyKind;\n// }\n\n// enum ClassLiteralPropertyKind {\n// \tMETHOD = 'METHOD',\n// \tGETTER = 'GETTER',\n// \tSETTER = 'SETTER',\n// \tFIELD = 'FIELD'\n// }\n\n// export class ClassLiteralProperty {\n// \tstatic Kind = ClassLiteralPropertyKind;\n// }\n\n// function assertUnreachable(x: never): never {\n// \tthrow new Error(`Didn't expect to get here`);\n// }\n// export function classPropertyKindFor(kind: PropertyKind): ClassLiteralPropertyKind {\n// \tswitch (kind) {\n// \t\tcase PropertyKind.AccessorGetter:\n// \t\t\treturn ClassLiteralPropertyKind.GETTER;\n// \t\tcase PropertyKind.AccessorSetter:\n// \t\t\treturn ClassLiteralPropertyKind.SETTER;\n// \t\tcase PropertyKind.Method:\n// \t\t\treturn ClassLiteralPropertyKind.METHOD;\n// \t\tcase PropertyKind.ClassField:\n// \t\t\treturn ClassLiteralPropertyKind.FIELD;\n// \t}\n// \tthrow new Error(`unexpected property kind: ${kind}`);\n// }\n\n// export enum VariableMode {\n// \tConst = 'Const',\n// \tPrivateMethod = 'PrivateMethod',\n// \tPrivateGetterOnly = 'PrivateGetterOnly',\n// \tPrivateSetterOnly = 'PrivateSetterOnly'\n// }\n\n// export function getVariableMode(kind: ClassLiteralPropertyKind): VariableMode {\n// \tswitch (kind) {\n// \t\tcase ClassLiteralPropertyKind.FIELD:\n// \t\t\treturn VariableMode.Const;\n// \t\tcase ClassLiteralPropertyKind.METHOD:\n// \t\t\treturn VariableMode.PrivateMethod;\n// \t\tcase ClassLiteralPropertyKind.GETTER:\n// \t\t\treturn VariableMode.PrivateGetterOnly;\n// \t\tcase ClassLiteralPropertyKind.SETTER:\n// \t\t\treturn VariableMode.PrivateSetterOnly;\n// \t}\n// }\n\n// export class JavaScriptAppParser extends JavaScriptParser {\n// \tprotected parseNewTargetExpression(): ExpressionNode {\n// \t\tthis.consume(Token.PERIOD);\n// \t\tconst target: ExpressionNode = this.parsePropertyName();\n// \t\tif (target.toString() !== 'target') {\n// \t\t\tthrow new Error(this.errorMessage(`Expression (new.${target.toString()}) not supported.`));\n// \t\t}\n// \t\treturn MetaProperty.NewTarget;\n// \t}\n// \tprotected parseClassDeclaration(names: ExpressionNode[] | undefined, defaultExport: boolean): ExpressionNode {\n// \t\t// ClassDeclaration ::\n// \t\t// 'class' Identifier ('extends' LeftHandExpression)? '{' ClassBody '}'\n// \t\t// 'class' ('extends' LeftHandExpression)? '{' ClassBody '}'\n// \t\t//\n// \t\t// The anonymous form is allowed iff [default_export] is true.\n// \t\t//\n// \t\t// 'class' is expected to be consumed by the caller.\n// \t\t//\n// \t\t// A ClassDeclaration\n// \t\t//\n// \t\t// class C { ... }\n// \t\t//\n// \t\t// has the same semantics as:\n// \t\t//\n// \t\t// let C = class C { ... };\n// \t\t//\n// \t\t// so rewrite it as such.\n\n// \t\tconst nextToken = this.peek().token;\n// \t\tconst isStrictReserved = Token.isStrictReservedWord(nextToken);\n// \t\tlet name: ExpressionNode | undefined;\n// \t\tlet variableName: ExpressionNode | undefined;\n// \t\tif (defaultExport && (nextToken == Token.EXTENDS || nextToken == Token.L_CURLY)) {\n// \t\t\tname = new Literal('default');\n// \t\t\tvariableName = new Literal('.default');\n// \t\t} else {\n// \t\t\tname = this.parseIdentifier();\n// \t\t\tvariableName = name;\n// \t\t}\n// \t\tconst value = this.parseClassLiteral(name, isStrictReserved);\n// \t\treturn this.declareClass(variableName, value, names);\n// \t}\n// \tprotected parseClassLiteral(name: ExpressionNode | undefined, nameIsStrictReserved: boolean): ExpressionNode {\n// \t\tconst isAnonymous = !!!name;\n\n// \t\t// All parts of a ClassDeclaration and ClassExpression are strict code.\n// \t\tif (!isAnonymous) {\n// \t\t\tif (nameIsStrictReserved) {\n// \t\t\t\tthrow new Error(this.errorMessage(`Unexpected Strict Reserved class name`));\n// \t\t\t}\n// \t\t\tif (this.isEvalOrArguments(name!)) {\n// \t\t\t\tthrow new Error(this.errorMessage(`Strict Eval Arguments not allowed for class name`));\n// \t\t\t}\n// \t\t}\n\n// \t\t// ClassScope * class_scope = NewClassScope(scope(), is_anonymous);\n// \t\t// BlockState block_state(& scope_, class_scope);\n// \t\t// RaiseLanguageMode(LanguageMode.kStrict);\n\n// \t\t// BlockState object_literal_scope_state(& object_literal_scope_, nullptr);\n\n// \t\t// ClassInfo classInfo(this);\n// \t\t// classInfo.is_anonymous = is_anonymous;\n\n// \t\tconst classInfo = { isAnonymous, computedFieldCount: 0 } as ClassInfo;\n\n// \t\t// scope() -> set_start_position(class_token_pos);\n// \t\tif (this.check(Token.EXTENDS)) {\n// \t\t\t// ClassScope.HeritageParsingScope heritage(class_scope);\n// \t\t\t// FuncNameInferrerState fni_state(& fni_);\n// \t\t\t// ExpressionParsingScope scope(impl());\n// \t\t\tclassInfo.extends = this.parseLeftHandSideExpression();\n// \t\t\t// scope.ValidateExpression();\n// \t\t}\n\n// \t\tthis.expect(Token.L_CURLY);\n\n// \t\tconst hasExtends = !(classInfo.extends === undefined);\n\n// \t\tconst staticBlockList: ExpressionNode[] = [];\n// \t\tconst privateClassMemberList: ExpressionNode[] = [];\n// \t\tconst publicClassFieldList: ExpressionNode[] = [];\n// \t\tconst publicClassMethodList: ExpressionNode[] = [];\n\n// \t\twhile (this.peek().isNotType(Token.R_CURLY)) {\n// \t\t\tif (this.check(Token.SEMICOLON)) continue;\n\n// \t\t\t// Either we're parsing a `static { }` initialization block or a property.\n// \t\t\tif (this.peek().isType(Token.STATIC) && this.peekAhead().isType(Token.L_CURLY)) {\n// \t\t\t\tconst staticBlock = this.parseClassStaticBlock(classInfo);\n// \t\t\t\tstaticBlockList.push(staticBlock);\n// \t\t\t\tcontinue;\n// \t\t\t}\n\n// \t\t\t// FuncNameInferrerState fni_state(& fni_);\n// \t\t\t// If we haven't seen the constructor yet, it potentially is the next\n// \t\t\t// property.\n// \t\t\tlet isConstructor = !classInfo.hasSeenConstructor;\n// \t\t\tconst propInfo = new ParsePropertyInfo();\n// \t\t\tpropInfo.position = PropertyPosition.ClassLiteral;\n\n// \t\t\tconst property = this.parseClassPropertyDefinition(classInfo, propInfo, hasExtends);\n\n// \t\t\t// if (has_error()) return impl() -> FailureExpression();\n\n// \t\t\tconst propertyKind = classPropertyKindFor(propInfo.kind);\n// \t\t\tif (!classInfo.hasStaticComputedNames && propInfo.isStatic && propInfo.isComputedName) {\n// \t\t\t\tclassInfo.hasStaticComputedNames = true;\n// \t\t\t}\n// \t\t\tisConstructor &&= classInfo.hasSeenConstructor;\n\n// \t\t\tconst isField = propertyKind == ClassLiteralPropertyKind.FIELD;\n\n// \t\t\tif (propInfo.isPrivate) {\n// \t\t\t\tif (isConstructor) {\n// \t\t\t\t\tthrow new Error(this.errorMessage('private constructor is not allowed'));\n// \t\t\t\t}\n// \t\t\t\tclassInfo.requiresBrand ||= (!isField && !propInfo.isStatic);\n// \t\t\t\tconst isMethod = propertyKind == ClassLiteralPropertyKind.METHOD;\n// \t\t\t\tclassInfo.hasPrivateMethods ||= isMethod;\n// \t\t\t\tclassInfo.hasStaticPrivateMethods ||= isMethod && propInfo.isStatic;\n// \t\t\t\tconst privateClassMember = this.declarePrivateClassMember(propInfo.name, property, propertyKind, propInfo.isStatic, classInfo);\n// \t\t\t\tprivateClassMemberList.push(privateClassMember);\n// \t\t\t\tcontinue;\n// \t\t\t}\n\n// \t\t\tif (isField) {\n// \t\t\t\tif (propInfo.isComputedName) {\n// \t\t\t\t\tclassInfo.computedFieldCount++;\n// \t\t\t\t}\n// \t\t\t\tconst publicClassField = this.declarePublicClassField(property, propInfo.isStatic, propInfo.isComputedName, classInfo);\n// \t\t\t\tpublicClassFieldList.push(publicClassField);\n// \t\t\t\tcontinue;\n// \t\t\t}\n\n// \t\t\tconst publicClassMethod = this.declarePublicClassMethod(name, property, isConstructor, classInfo);\n// \t\t\tpublicClassMethodList.push(publicClassMethod);\n// \t\t}\n\n// \t\tthis.expect(Token.R_CURLY);\n// \t\t// int end_pos = end_position();\n// \t\t// class_scope -> set_end_position(end_pos);\n\n// \t\t// VariableProxy * unresolvable = class_scope -> ResolvePrivateNamesPartially();\n// \t\t// if (unresolvable != nullptr) {\n// \t\t// \timpl() -> ReportMessageAt(Scanner.Location(unresolvable -> position(),unresolvable -> position() + 1),\n// \t\t// \t\tMessageTemplate.kInvalidPrivateFieldResolution,\n// \t\t// \t\tunresolvable -> raw_name());\n// \t\t// \treturn impl() -> FailureExpression();\n// \t\t// }\n\n// \t\t// if (classInfo.requiresBrand) {\n// \t\t// \tclass_scope -> DeclareBrandVariable(ast_value_factory(), IsStaticFlag.kNotStatic, kNoSourcePosition);\n// \t\t// }\n\n// \t\t// if (class_scope -> needs_home_object()) {\n// \t\t// \tclassInfo.homeObjectVariable = class_scope -> DeclareHomeObjectVariable(ast_value_factory());\n// \t\t// \tclassInfo.staticHomeObjectVariable = class_scope -> DeclareStaticHomeObjectVariable(ast_value_factory());\n// \t\t// }\n\n// \t\t// bool should_save_class_variable_index = class_scope -> should_save_class_variable_index();\n// \t\t// if (!isAnonymous || should_save_class_variable_index) {\n// \t\t// \tthis.declareClassVariable(name, classInfo);\n// \t\t// \tif (should_save_class_variable_index) {\n// \t\t// \t\tclass_scope -> class_variable() -> set_is_used();\n// \t\t// \t\tclass_scope -> class_variable() -> ForceContextAllocation();\n// \t\t// \t}\n// \t\t// }\n// \t\treturn this.rewriteClassLiteral(name, classInfo);\n// \t}\n// \tprotected declarePublicClassMethod(name: ExpressionNode | undefined, property: ExpressionNode, isConstructor: boolean, classInfo: ClassInfo): ExpressionNode {\n// \t\tthrow new Error('Method not implemented.');\n// \t}\n// \tprotected declarePublicClassField(property: ExpressionNode, isStatic: boolean, isComputedName: boolean, classInfo: ClassInfo): ExpressionNode {\n// \t\tthrow new Error('Method not implemented.');\n// \t}\n// \tprotected inferFunctionName() {\n// \t\tthrow new Error('Method not implemented.');\n// \t}\n// \tprotected declarePrivateClassMember(name: string, property: ExpressionNode, propertyKind: ClassLiteralPropertyKind, isStatic: boolean, classInfo: ClassInfo): ExpressionNode {\n// \t\tthrow new Error('Method not implemented.');\n// \t}\n// \tprotected parseClassPropertyDefinition(classInfo: ClassInfo, propInfo: ParsePropertyInfo, hasExtends: boolean): ExpressionNode {\n// \t\tif (!classInfo) {\n// \t\t\tthrow new Error(this.errorMessage('class info is undefined'));\n// \t\t}\n// \t\tif (propInfo.position !== PropertyPosition.ClassLiteral) {\n// \t\t\tthrow new Error(this.errorMessage('expected property position ClassLiteral'));\n// \t\t}\n\n// \t\tconst nameToken = this.peek();\n// \t\tlet nameExpression: ExpressionNode;\n// \t\tif (nameToken.isType(Token.STATIC)) {\n// \t\t\tthis.consume(Token.STATIC);\n// \t\t\tif (this.peek().isType(Token.L_PARENTHESES)) {\n// \t\t\t\tpropInfo.kind = PropertyKind.Method;\n// \t\t\t\tnameExpression = this.parseIdentifier();\n// \t\t\t\tpropInfo.name = (nameExpression as Identifier).getName() as string;\n// \t\t\t} else if (this.peek().isType(Token.ASSIGN)\n// \t\t\t\t|| this.peek().isType(Token.SEMICOLON)\n// \t\t\t\t|| this.peek().isType(Token.R_BRACKETS)) {\n// \t\t\t\tnameExpression = this.parseIdentifier();\n// \t\t\t\tpropInfo.name = (nameExpression as Identifier).getName() as string;\n// \t\t\t} else {\n// \t\t\t\tpropInfo.isStatic = true;\n// \t\t\t\tnameExpression = this.parseProperty(propInfo);\n// \t\t\t}\n// \t\t} else {\n// \t\t\tnameExpression = this.parseProperty(propInfo);\n// \t\t}\n\n// \t\tswitch (propInfo.kind) {\n// \t\t\tcase PropertyKind.Assign:\n// \t\t\tcase PropertyKind.ClassField:\n// \t\t\tcase PropertyKind.ShorthandOrClassField:\n// \t\t\tcase PropertyKind.NotSet: {\n// \t\t\t\t// This case is a name followed by a\n// \t\t\t\t// name or other property. Here we have\n// \t\t\t\t// to assume that's an uninitialized\n// \t\t\t\t// field followed by a line break\n// \t\t\t\t// followed by a property, with ASI\n// \t\t\t\t// adding the semicolon. If not, there\n// \t\t\t\t// will be a syntax error after parsing\n// \t\t\t\t// the first name as an uninitialized\n// \t\t\t\t// field.\n// \t\t\t\tpropInfo.kind = PropertyKind.ClassField;\n\n// \t\t\t\t// if (!propInfo.isComputedName) {\n// \t\t\t\t// \tthis.checkClassFieldName(propInfo.name, propInfo.isStatic);\n// \t\t\t\t// }\n\n// \t\t\t\tconst initializer: ExpressionNode = this.parseMemberInitializer(classInfo, propInfo.isStatic);\n// \t\t\t\tthis.expectSemicolon();\n\n// \t\t\t\tconst result: ExpressionNode = this.newClassLiteralProperty(\n// \t\t\t\t\tnameExpression,\n// \t\t\t\t\tinitializer,\n// \t\t\t\t\tClassLiteralPropertyKind.FIELD,\n// \t\t\t\t\tpropInfo.isStatic,\n// \t\t\t\t\tpropInfo.isComputedName,\n// \t\t\t\t\tpropInfo.isPrivate\n// \t\t\t\t);\n// \t\t\t\tthis.setFunctionNameFromPropertyName(result, propInfo.name);\n// \t\t\t\treturn result;\n// \t\t\t}\n// \t\t\tcase PropertyKind.Method: {\n// \t\t\t\t// MethodDefinition\n// \t\t\t\t// PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}'\n// \t\t\t\t// '*' PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}'\n// \t\t\t\t// async PropertyName '(' StrictFormalParameters ')'\n// \t\t\t\t// '{' FunctionBody '}'\n// \t\t\t\t// async '*' PropertyName '(' StrictFormalParameters ')'\n// \t\t\t\t// '{' FunctionBody '}'\n\n// \t\t\t\t// if (!propInfo.isComputedName) {\n// \t\t\t\t// \tthis.checkClassMethodName(propInfo.name, PropertyKind.Method,propInfo.functionFlags, propInfo.isStatic,classInfo . hasSeenConstructor);\n// \t\t\t\t// }\n\n// \t\t\t\tlet kind: FunctionKind = this.methodKindFor(propInfo.isStatic, propInfo.funcFlag);\n\n// \t\t\t\tif (!propInfo.isStatic && propInfo.name.toString() === 'constructor') {\n// \t\t\t\t\tclassInfo.hasSeenConstructor = true;\n// \t\t\t\t\tkind = hasExtends ? FunctionKind.DERIVED_CONSTRUCTOR : FunctionKind.BASE_CONSTRUCTOR;\n// \t\t\t\t}\n\n// \t\t\t\tconst value = this.parseFunctionLiteral(\n// \t\t\t\t\tkind,\n// \t\t\t\t\tpropInfo.name\n// \t\t\t\t\t// ,kSkipFunctionNameCheck, kind, FunctionSyntaxKind.kAccessorOrMethod\n// \t\t\t\t);\n\n// \t\t\t\tClassLiteralPropertyT result = factory() -> NewClassLiteralProperty(\n// \t\t\t\t\tname_expression, value, ClassLiteralProperty.METHOD,\n// \t\t\t\t\tpropInfo.is_static, propInfo.is_computed_name,\n// \t\t\t\t\tpropInfo.is_private);\n// \t\t\t\tthis.setFunctionNameFromPropertyName(result, propInfo.name);\n// \t\t\t\treturn result;\n// \t\t\t}\n\n// \t\t\tcase PropertyKind.AccessorGetter:\n// \t\t\tcase PropertyKind.AccessorSetter: {\n// \t\t\t\tDCHECK_EQ(propInfo.function_flags, ParseFunctionFlag.kIsNormal);\n// \t\t\t\tbool is_get = propInfo.kind == PropertyKind.kAccessorGetter;\n\n// \t\t\t\tif (!propInfo.is_computed_name) {\n// \t\t\t\t\tCheckClassMethodName(propInfo.name, propInfo.kind,\n// \t\t\t\t\t\tParseFunctionFlag.kIsNormal, propInfo.is_static,\n// & class_info -> has_seen_constructor);\n// \t\t\t\t\t// Make sure the name expression is a string since we need a Name for\n// \t\t\t\t\t// Runtime_DefineAccessorPropertyUnchecked and since we can determine\n// \t\t\t\t\t// this statically we can skip the extra runtime check.\n// \t\t\t\t\tname_expression = factory() -> NewStringLiteral(\n// \t\t\t\t\t\tpropInfo.name, name_expression -> position());\n// \t\t\t\t}\n\n// \t\t\t\tlet kind: FunctionKind;\n// \t\t\t\tif (propInfo.is_static) {\n// \t\t\t\t\tkind = is_get ? FunctionKind.StaticGetterFunction\n// \t\t\t\t\t\t: FunctionKind.StaticSetterFunction;\n// \t\t\t\t} else {\n// \t\t\t\t\tkind = is_get ? FunctionKind.GetterFunction\n// \t\t\t\t\t\t: FunctionKind.SetterFunction;\n// \t\t\t\t}\n\n// \t\t\t\tFunctionLiteralT value = impl() -> ParseFunctionLiteral(\n// \t\t\t\t\tpropInfo.name, scanner() -> location(), kSkipFunctionNameCheck, kind,\n// \t\t\t\t\tname_token_position, FunctionSyntaxKind.kAccessorOrMethod,\n// \t\t\t\t\tlanguage_mode(), nullptr);\n\n// \t\t\t\tClassLiteralPropertyKind property_kind =\n// \t\t\t\t\tis_get ? ClassLiteralProperty.GETTER : ClassLiteralProperty.SETTER;\n// \t\t\t\tClassLiteralPropertyT result = factory() -> NewClassLiteralProperty(\n// \t\t\t\t\t\tname_expression, value, property_kind, propInfo.is_static,\n// \t\t\t\t\t\tpropInfo.is_computed_name, propInfo.is_private);\n// \t\t\t\tconst AstRawString* prefix =\n// \t\t\t\tis_get ? ast_value_factory() -> get_space_string()\n// \t\t\t\t\t: ast_value_factory() -> set_space_string();\n// \t\t\t\tthis.setFunctionNameFromPropertyName(result, propInfo.name, prefix);\n// \t\t\t\treturn result;\n// \t\t\t}\n// \t\t\tcase PropertyKind.Value:\n// \t\t\tcase PropertyKind.Shorthand:\n// \t\t\tcase PropertyKind.Spread:\n// \t\t\t\t// throw new Error(this.errorMessage('Report Unexpected Token'));\n// \t\t\t\treturn NullNode;\n// \t\t}\n// \t\tthrow new Error(this.errorMessage('UNREACHABLE'));\n// \t}\n// \tsetFunctionNameFromPropertyName(property: LiteralProperty, name: string, prefix?: string): void {\n// \t\t// Ignore \"__proto__\" as a name when it's being used to set the [[Prototype]]\n// \t\t// of an object literal.\n// \t\t// See ES #sec-__proto__-property-names-in-object-initializers.\n\n// \t\tif (property instanceof Identifier && property.getName() === '__proto__') {\n// \t\t\treturn;\n// \t\t}\n\n// \t\t// if (property -> IsPrototype() || has_error()) return;\n\n// \t\t// DCHECK(!property -> value() -> IsAnonymousFunctionDefinition() ||\n// \t\t// \tproperty -> kind() == ObjectLiteralProperty:: COMPUTED);\n\n// \t\t// SetFunctionNameFromPropertyName(static_cast < LiteralProperty *> (property), name,\n// \t\t// \tprefix);\n// \t}\n// \tprotected methodKindFor(isStatic: boolean, functionFlags: FunctionKind): FunctionKind {\n// \t\tconst isGenerator = functionFlags.includes('GENERATOR');\n// \t\tconst isAsync = functionFlags.includes('ASYNC');\n// \t\treturn functionKindForImpl(\n// \t\t\tisStatic ? SubFunctionKind.StaticMethod : SubFunctionKind.NonStaticMethod,\n// \t\t\tisGenerator,\n// \t\t\tisAsync\n// \t\t);\n// \t}\n// \tnewClassLiteralProperty(nameExpression: ExpressionNode, initializer: ExpressionNode, FIELD: ClassLiteralPropertyKind, isStatic: boolean, isComputedName: boolean, isPrivate: boolean): ExpressionNode {\n// \t\tthrow new Error('Method not implemented.');\n// \t}\n// \tparseMemberInitializer(classInfo: ClassInfo, isStatic: boolean): ExpressionNode {\n// \t\tthrow new Error('Method not implemented.');\n// \t}\n// \tprotected parseClassStaticBlock(classInfo: ClassInfo): ExpressionNode {\n// \t\tthis.consume(Token.STATIC);\n// \t\t// Each static block has its own var and lexical scope, so make a new var\n// \t\t// block scope instead of using the synthetic members initializer function\n// \t\t// scope.\n// \t\tconst staticBlock = this.parseBlock();\n// \t\tclassInfo.hasStaticElements = true;\n// \t\treturn staticBlock;\n\n// \t}\n// \tprotected declareClass(variableName: ExpressionNode | undefined, value: ExpressionNode, names: ExpressionNode[] | undefined): ExpressionNode {\n// \t\tif (names && variableName) {\n// \t\t\tconst proxy = this.declareVariable(variableName, 'let');\n// \t\t\tnames.push(variableName);\n// \t\t\treturn new AssignmentExpression('=', proxy, value);\n// \t\t}\n// \t\treturn value;\n// \t}\n// \tprotected parseSuperExpression(): ExpressionNode {\n// \t\tthrow new Error(this.errorMessage('Expression (supper) not supported.'));\n// \t}\n// \tprotected parseImportExpressions(): ExpressionNode {\n// \t\tthrow new Error(this.errorMessage('Expression (import) not supported.'));\n// \t}\n// \tprotected declareVariable(name: ExpressionNode | undefined, mode: 'let' | 'const' | 'var') {\n// \t\tif (!name) {\n// \t\t\tthrow new Error(this.errorMessage('Variable name is undefined'));\n// \t\t}\n// \t\tswitch (mode) {\n// \t\t\tcase 'const':\n// \t\t\t\treturn new VariableDeclarationNode([new VariableNode(name as CanDeclareExpression)], 'const');\n// \t\t\tdefault:\n// \t\t\tcase 'var':\n// \t\t\t\treturn new VariableDeclarationNode([new VariableNode(name as CanDeclareExpression)], 'var');\n// \t\t\tcase 'let':\n// \t\t\t\treturn new VariableDeclarationNode([new VariableNode(name as CanDeclareExpression)], 'let');\n// \t\t}\n// \t}\n// }\n"]}
|
package/v8/parser.d.ts
CHANGED
|
@@ -82,7 +82,7 @@ export declare abstract class AbstractParser {
|
|
|
82
82
|
protected errorMessage(message: string): string;
|
|
83
83
|
}
|
|
84
84
|
export declare class JavaScriptParser extends AbstractParser {
|
|
85
|
-
static parse(
|
|
85
|
+
static parse(source: string | TokenExpression[] | TokenStream): ExpressionNode;
|
|
86
86
|
scan(): ExpressionNode;
|
|
87
87
|
protected parseStatement(): ExpressionNode;
|
|
88
88
|
protected parseTryStatement(): ExpressionNode;
|
|
@@ -106,7 +106,7 @@ export declare class JavaScriptParser extends AbstractParser {
|
|
|
106
106
|
protected parseFunctionDeclaration(): ExpressionNode;
|
|
107
107
|
protected parseFunctionDeclarationAndGenerator(): ExpressionNode;
|
|
108
108
|
protected parseHoistableDeclaration(flag: FunctionKind): ExpressionNode;
|
|
109
|
-
protected parseIdentifier(): ExpressionNode
|
|
109
|
+
protected parseIdentifier(): ExpressionNode;
|
|
110
110
|
protected getIdentifier(): ExpressionNode;
|
|
111
111
|
protected parseFunctionLiteral(flag: FunctionKind, name?: ExpressionNode): ExpressionNode;
|
|
112
112
|
protected parseArrowFunctionBody(): ExpressionNode | ExpressionNode[];
|
package/v8/parser.js
CHANGED
|
@@ -251,8 +251,10 @@ export class AbstractParser {
|
|
|
251
251
|
}
|
|
252
252
|
}
|
|
253
253
|
export class JavaScriptParser extends AbstractParser {
|
|
254
|
-
static parse(
|
|
255
|
-
const stream =
|
|
254
|
+
static parse(source) {
|
|
255
|
+
const stream = (typeof source === 'string' || Array.isArray(source))
|
|
256
|
+
? TokenStream.getTokenStream(source)
|
|
257
|
+
: source;
|
|
256
258
|
const parser = new JavaScriptParser(stream);
|
|
257
259
|
return parser.scan();
|
|
258
260
|
}
|