@typespec/compiler 0.67.0-dev.9 → 0.67.0
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/dist/generated-defs/TypeSpec.d.ts +28 -1
- package/dist/generated-defs/TypeSpec.d.ts.map +1 -1
- package/dist/manifest.js +2 -2
- package/dist/src/ast/index.d.ts +14 -0
- package/dist/src/ast/index.d.ts.map +1 -0
- package/dist/src/ast/index.js +13 -0
- package/dist/src/ast/index.js.map +1 -0
- package/dist/src/config/config-loader.d.ts.map +1 -1
- package/dist/src/config/config-loader.js +2 -1
- package/dist/src/config/config-loader.js.map +1 -1
- package/dist/src/config/config-to-options.d.ts.map +1 -1
- package/dist/src/config/config-to-options.js +2 -1
- package/dist/src/config/config-to-options.js.map +1 -1
- package/dist/src/core/binder.d.ts.map +1 -1
- package/dist/src/core/binder.js +18 -137
- package/dist/src/core/binder.js.map +1 -1
- package/dist/src/core/checker.d.ts +7 -23
- package/dist/src/core/checker.d.ts.map +1 -1
- package/dist/src/core/checker.js +59 -780
- package/dist/src/core/checker.js.map +1 -1
- package/dist/src/core/cli/actions/compile/args.d.ts +1 -0
- package/dist/src/core/cli/actions/compile/args.d.ts.map +1 -1
- package/dist/src/core/cli/actions/compile/args.js +3 -0
- package/dist/src/core/cli/actions/compile/args.js.map +1 -1
- package/dist/src/core/cli/actions/compile/compile.js +1 -1
- package/dist/src/core/cli/actions/compile/compile.js.map +1 -1
- package/dist/src/core/cli/cli.js +14 -4
- package/dist/src/core/cli/cli.js.map +1 -1
- package/dist/src/core/cli/utils.d.ts.map +1 -1
- package/dist/src/core/cli/utils.js +5 -1
- package/dist/src/core/cli/utils.js.map +1 -1
- package/dist/src/core/decorator-utils.d.ts.map +1 -1
- package/dist/src/core/decorator-utils.js +1 -3
- package/dist/src/core/decorator-utils.js.map +1 -1
- package/dist/src/core/diagnostic-error.d.ts +7 -0
- package/dist/src/core/diagnostic-error.d.ts.map +1 -0
- package/dist/src/core/diagnostic-error.js +9 -0
- package/dist/src/core/diagnostic-error.js.map +1 -0
- package/dist/src/core/diagnostics.d.ts +6 -6
- package/dist/src/core/diagnostics.d.ts.map +1 -1
- package/dist/src/core/diagnostics.js +10 -11
- package/dist/src/core/diagnostics.js.map +1 -1
- package/dist/src/core/emitter-utils.js +2 -2
- package/dist/src/core/emitter-utils.js.map +1 -1
- package/dist/src/core/entrypoint-resolution.d.ts.map +1 -1
- package/dist/src/core/entrypoint-resolution.js +2 -1
- package/dist/src/core/entrypoint-resolution.js.map +1 -1
- package/dist/src/core/helpers/discriminator-utils.d.ts +1 -6
- package/dist/src/core/helpers/discriminator-utils.d.ts.map +1 -1
- package/dist/src/core/helpers/discriminator-utils.js +1 -57
- package/dist/src/core/helpers/discriminator-utils.js.map +1 -1
- package/dist/src/core/helpers/index.d.ts +1 -1
- package/dist/src/core/helpers/index.d.ts.map +1 -1
- package/dist/src/core/helpers/index.js +1 -1
- package/dist/src/core/helpers/index.js.map +1 -1
- package/dist/src/core/helpers/syntax-utils.d.ts +2 -1
- package/dist/src/core/helpers/syntax-utils.d.ts.map +1 -1
- package/dist/src/core/helpers/syntax-utils.js +8 -4
- package/dist/src/core/helpers/syntax-utils.js.map +1 -1
- package/dist/src/core/inspector/symbol.d.ts.map +1 -1
- package/dist/src/core/inspector/symbol.js +9 -11
- package/dist/src/core/inspector/symbol.js.map +1 -1
- package/dist/src/core/js-marshaller.d.ts +0 -9
- package/dist/src/core/js-marshaller.d.ts.map +1 -1
- package/dist/src/core/js-marshaller.js +0 -26
- package/dist/src/core/js-marshaller.js.map +1 -1
- package/dist/src/core/logger/console-sink.browser.d.ts.map +1 -1
- package/dist/src/core/logger/console-sink.browser.js +0 -16
- package/dist/src/core/logger/console-sink.browser.js.map +1 -1
- package/dist/src/core/logger/console-sink.d.ts +2 -3
- package/dist/src/core/logger/console-sink.d.ts.map +1 -1
- package/dist/src/core/logger/console-sink.js +16 -43
- package/dist/src/core/logger/console-sink.js.map +1 -1
- package/dist/src/core/logger/dynamic-task.d.ts +16 -0
- package/dist/src/core/logger/dynamic-task.d.ts.map +1 -0
- package/dist/src/core/logger/dynamic-task.js +93 -0
- package/dist/src/core/logger/dynamic-task.js.map +1 -0
- package/dist/src/core/logger/logger.d.ts.map +1 -1
- package/dist/src/core/logger/logger.js +11 -1
- package/dist/src/core/logger/logger.js.map +1 -1
- package/dist/src/core/messages.d.ts +35 -45
- package/dist/src/core/messages.d.ts.map +1 -1
- package/dist/src/core/messages.js +9 -11
- package/dist/src/core/messages.js.map +1 -1
- package/dist/src/core/name-resolver.d.ts.map +1 -1
- package/dist/src/core/name-resolver.js +12 -23
- package/dist/src/core/name-resolver.js.map +1 -1
- package/dist/src/core/node-host.d.ts +0 -3
- package/dist/src/core/node-host.d.ts.map +1 -1
- package/dist/src/core/node-host.js +5 -51
- package/dist/src/core/node-host.js.map +1 -1
- package/dist/src/core/node-system-host.d.ts +9 -0
- package/dist/src/core/node-system-host.d.ts.map +1 -0
- package/dist/src/core/node-system-host.js +57 -0
- package/dist/src/core/node-system-host.js.map +1 -0
- package/dist/src/core/options.d.ts +9 -0
- package/dist/src/core/options.d.ts.map +1 -1
- package/dist/src/core/parser.d.ts.map +1 -1
- package/dist/src/core/parser.js +50 -654
- package/dist/src/core/parser.js.map +1 -1
- package/dist/src/core/program.d.ts +6 -16
- package/dist/src/core/program.d.ts.map +1 -1
- package/dist/src/core/program.js +48 -24
- package/dist/src/core/program.js.map +1 -1
- package/dist/src/core/scanner.d.ts +37 -1
- package/dist/src/core/scanner.d.ts.map +1 -1
- package/dist/src/core/scanner.js +150 -3
- package/dist/src/core/scanner.js.map +1 -1
- package/dist/src/core/semantic-walker.d.ts.map +1 -1
- package/dist/src/core/semantic-walker.js +0 -9
- package/dist/src/core/semantic-walker.js.map +1 -1
- package/dist/src/core/source-loader.d.ts.map +1 -1
- package/dist/src/core/source-loader.js +2 -1
- package/dist/src/core/source-loader.js.map +1 -1
- package/dist/src/core/state-accessors.d.ts +53 -12
- package/dist/src/core/state-accessors.d.ts.map +1 -1
- package/dist/src/core/state-accessors.js +75 -48
- package/dist/src/core/state-accessors.js.map +1 -1
- package/dist/src/core/type-relation-checker.d.ts.map +1 -1
- package/dist/src/core/type-relation-checker.js +4 -22
- package/dist/src/core/type-relation-checker.js.map +1 -1
- package/dist/src/core/type-utils.js +2 -2
- package/dist/src/core/type-utils.js.map +1 -1
- package/dist/src/core/types.d.ts +58 -324
- package/dist/src/core/types.d.ts.map +1 -1
- package/dist/src/core/types.js +24 -55
- package/dist/src/core/types.js.map +1 -1
- package/dist/src/core/visibility/lifecycle.d.ts.map +1 -1
- package/dist/src/core/visibility/lifecycle.js +2 -11
- package/dist/src/core/visibility/lifecycle.js.map +1 -1
- package/dist/src/emitter-framework/asset-emitter.js +2 -2
- package/dist/src/emitter-framework/asset-emitter.js.map +1 -1
- package/dist/src/emitter-framework/index.d.ts +74 -8
- package/dist/src/emitter-framework/index.d.ts.map +1 -1
- package/dist/src/emitter-framework/index.js +32 -8
- package/dist/src/emitter-framework/index.js.map +1 -1
- package/dist/src/experimental/freeze-graph.d.ts.map +1 -1
- package/dist/src/experimental/freeze-graph.js +0 -3
- package/dist/src/experimental/freeze-graph.js.map +1 -1
- package/dist/src/experimental/mutators.d.ts +2 -2
- package/dist/src/experimental/mutators.d.ts.map +1 -1
- package/dist/src/experimental/mutators.js +1 -7
- package/dist/src/experimental/mutators.js.map +1 -1
- package/dist/src/experimental/typekit/kits/model.d.ts +6 -0
- package/dist/src/experimental/typekit/kits/model.d.ts.map +1 -1
- package/dist/src/experimental/typekit/kits/model.js +10 -0
- package/dist/src/experimental/typekit/kits/model.js.map +1 -1
- package/dist/src/experimental/typekit/kits/type.d.ts +0 -6
- package/dist/src/experimental/typekit/kits/type.d.ts.map +1 -1
- package/dist/src/experimental/typekit/kits/type.js +15 -9
- package/dist/src/experimental/typekit/kits/type.js.map +1 -1
- package/dist/src/experimental/typekit/kits/union.d.ts +6 -0
- package/dist/src/experimental/typekit/kits/union.d.ts.map +1 -1
- package/dist/src/experimental/typekit/kits/union.js +4 -0
- package/dist/src/experimental/typekit/kits/union.js.map +1 -1
- package/dist/src/formatter/print/comment-handler.js +1 -0
- package/dist/src/formatter/print/comment-handler.js.map +1 -1
- package/dist/src/formatter/print/needs-parens.d.ts.map +1 -1
- package/dist/src/formatter/print/needs-parens.js +0 -4
- package/dist/src/formatter/print/needs-parens.js.map +1 -1
- package/dist/src/formatter/print/printer.d.ts +4 -12
- package/dist/src/formatter/print/printer.d.ts.map +1 -1
- package/dist/src/formatter/print/printer.js +14 -196
- package/dist/src/formatter/print/printer.js.map +1 -1
- package/dist/src/index.d.ts +11 -14
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +17 -13
- package/dist/src/index.js.map +1 -1
- package/dist/src/init/core-templates.d.ts +2 -2
- package/dist/src/init/core-templates.d.ts.map +1 -1
- package/dist/src/init/core-templates.js.map +1 -1
- package/dist/src/init/init.d.ts +0 -2
- package/dist/src/init/init.d.ts.map +1 -1
- package/dist/src/init/init.js +17 -51
- package/dist/src/init/init.js.map +1 -1
- package/dist/src/init/scaffold.d.ts +4 -3
- package/dist/src/init/scaffold.d.ts.map +1 -1
- package/dist/src/init/scaffold.js +3 -4
- package/dist/src/init/scaffold.js.map +1 -1
- package/dist/src/install/config.d.ts +9 -0
- package/dist/src/install/config.d.ts.map +1 -0
- package/dist/src/install/config.js +16 -0
- package/dist/src/install/config.js.map +1 -0
- package/dist/src/install/install.d.ts +14 -0
- package/dist/src/install/install.d.ts.map +1 -0
- package/dist/src/install/install.js +191 -0
- package/dist/src/install/install.js.map +1 -0
- package/dist/src/install/spec.d.ts +39 -0
- package/dist/src/install/spec.d.ts.map +1 -0
- package/dist/src/install/spec.js +152 -0
- package/dist/src/install/spec.js.map +1 -0
- package/dist/src/internals/index.d.ts +8 -0
- package/dist/src/internals/index.d.ts.map +1 -0
- package/dist/src/internals/index.js +11 -0
- package/dist/src/internals/index.js.map +1 -0
- package/dist/src/lib/decorators.d.ts +16 -4
- package/dist/src/lib/decorators.d.ts.map +1 -1
- package/dist/src/lib/decorators.js +86 -46
- package/dist/src/lib/decorators.js.map +1 -1
- package/dist/src/lib/examples.js +1 -5
- package/dist/src/lib/examples.js.map +1 -1
- package/dist/src/lib/service.d.ts.map +1 -1
- package/dist/src/lib/service.js +0 -4
- package/dist/src/lib/service.js.map +1 -1
- package/dist/src/lib/tsp-index.d.ts.map +1 -1
- package/dist/src/lib/tsp-index.js +2 -2
- package/dist/src/lib/tsp-index.js.map +1 -1
- package/dist/src/module-resolver/module-resolver.d.ts.map +1 -1
- package/dist/src/module-resolver/module-resolver.js +20 -13
- package/dist/src/module-resolver/module-resolver.js.map +1 -1
- package/dist/src/package-manger/npm-registry-utils.d.ts +83 -0
- package/dist/src/package-manger/npm-registry-utils.d.ts.map +1 -0
- package/dist/src/package-manger/npm-registry-utils.js +42 -0
- package/dist/src/package-manger/npm-registry-utils.js.map +1 -0
- package/dist/src/server/classify.d.ts.map +1 -1
- package/dist/src/server/classify.js +0 -26
- package/dist/src/server/classify.js.map +1 -1
- package/dist/src/server/compile-service.d.ts.map +1 -1
- package/dist/src/server/compile-service.js +2 -1
- package/dist/src/server/compile-service.js.map +1 -1
- package/dist/src/server/completion.d.ts.map +1 -1
- package/dist/src/server/completion.js +21 -10
- package/dist/src/server/completion.js.map +1 -1
- package/dist/src/server/constants.js +1 -1
- package/dist/src/server/server.js +1 -1
- package/dist/src/server/server.js.map +1 -1
- package/dist/src/server/serverlib.d.ts.map +1 -1
- package/dist/src/server/serverlib.js +2 -1
- package/dist/src/server/serverlib.js.map +1 -1
- package/dist/src/server/tmlanguage.d.ts.map +1 -1
- package/dist/src/server/tmlanguage.js +0 -125
- package/dist/src/server/tmlanguage.js.map +1 -1
- package/dist/src/server/type-signature.js +4 -15
- package/dist/src/server/type-signature.js.map +1 -1
- package/dist/src/testing/code-fix-testing.js +1 -1
- package/dist/src/testing/code-fix-testing.js.map +1 -1
- package/dist/src/testing/expect.d.ts +1 -7
- package/dist/src/testing/expect.d.ts.map +1 -1
- package/dist/src/testing/expect.js +0 -12
- package/dist/src/testing/expect.js.map +1 -1
- package/dist/src/testing/index.d.ts +6 -6
- package/dist/src/testing/index.d.ts.map +1 -1
- package/dist/src/testing/index.js +5 -6
- package/dist/src/testing/index.js.map +1 -1
- package/dist/src/testing/source-utils.d.ts +20 -0
- package/dist/src/testing/source-utils.d.ts.map +1 -0
- package/dist/src/testing/source-utils.js +23 -0
- package/dist/src/testing/source-utils.js.map +1 -0
- package/dist/src/testing/test-host.d.ts.map +1 -1
- package/dist/src/testing/test-host.js +0 -4
- package/dist/src/testing/test-host.js.map +1 -1
- package/dist/src/testing/test-server-host.d.ts +0 -19
- package/dist/src/testing/test-server-host.d.ts.map +1 -1
- package/dist/src/testing/test-server-host.js +0 -22
- package/dist/src/testing/test-server-host.js.map +1 -1
- package/dist/src/testing/test-utils.js +1 -1
- package/dist/src/testing/test-utils.js.map +1 -1
- package/dist/src/types/package-json.d.ts +14 -0
- package/dist/src/types/package-json.d.ts.map +1 -1
- package/dist/src/utils/custom-key-map.d.ts.map +1 -0
- package/dist/src/utils/custom-key-map.js.map +1 -0
- package/dist/src/utils/fs-utils.d.ts +3 -0
- package/dist/src/utils/fs-utils.d.ts.map +1 -0
- package/dist/src/utils/fs-utils.js +19 -0
- package/dist/src/utils/fs-utils.js.map +1 -0
- package/dist/src/utils/io.d.ts +16 -0
- package/dist/src/utils/io.d.ts.map +1 -0
- package/dist/src/utils/io.js +77 -0
- package/dist/src/utils/io.js.map +1 -0
- package/dist/src/utils/misc.d.ts +4 -18
- package/dist/src/utils/misc.d.ts.map +1 -1
- package/dist/src/utils/misc.js +1 -77
- package/dist/src/utils/misc.js.map +1 -1
- package/dist/typespec.tmLanguage +0 -342
- package/lib/std/decorators.tsp +37 -2
- package/package.json +13 -7
- package/templates/__snapshots__/emitter-ts/src/emitter.ts +4 -6
- package/templates/emitter-ts/src/emitter.ts +4 -6
- package/templates/scaffolding.json +4 -4
- package/dist/src/core/helpers/projected-names-utils.d.ts +0 -20
- package/dist/src/core/helpers/projected-names-utils.d.ts.map +0 -1
- package/dist/src/core/helpers/projected-names-utils.js +0 -42
- package/dist/src/core/helpers/projected-names-utils.js.map +0 -1
- package/dist/src/core/install.d.ts +0 -3
- package/dist/src/core/install.d.ts.map +0 -1
- package/dist/src/core/install.js +0 -60
- package/dist/src/core/install.js.map +0 -1
- package/dist/src/core/projected-program.d.ts +0 -3
- package/dist/src/core/projected-program.d.ts.map +0 -1
- package/dist/src/core/projected-program.js +0 -4
- package/dist/src/core/projected-program.js.map +0 -1
- package/dist/src/core/projection-members.d.ts +0 -8
- package/dist/src/core/projection-members.d.ts.map +0 -1
- package/dist/src/core/projection-members.js +0 -382
- package/dist/src/core/projection-members.js.map +0 -1
- package/dist/src/core/projector.d.ts +0 -26
- package/dist/src/core/projector.d.ts.map +0 -1
- package/dist/src/core/projector.js +0 -572
- package/dist/src/core/projector.js.map +0 -1
- package/dist/src/emitter-framework/custom-key-map.d.ts.map +0 -1
- package/dist/src/emitter-framework/custom-key-map.js.map +0 -1
- /package/dist/src/{emitter-framework → utils}/custom-key-map.d.ts +0 -0
- /package/dist/src/{emitter-framework → utils}/custom-key-map.js +0 -0
package/dist/src/core/parser.js
CHANGED
|
@@ -2,7 +2,7 @@ import { isArray, mutate } from "../utils/misc.js";
|
|
|
2
2
|
import { codePointBefore, isIdentifierContinue, trim } from "./charcode.js";
|
|
3
3
|
import { compilerAssert } from "./diagnostics.js";
|
|
4
4
|
import { createDiagnostic } from "./messages.js";
|
|
5
|
-
import { createScanner, isComment, isKeyword, isPunctuation, isStatementKeyword, isTrivia, skipContinuousIdentifier, skipTrivia, skipTriviaBackward, Token, TokenDisplay, TokenFlags, } from "./scanner.js";
|
|
5
|
+
import { createScanner, isComment, isKeyword, isPunctuation, isReservedKeyword, isStatementKeyword, isTrivia, skipContinuousIdentifier, skipTrivia, skipTriviaBackward, Token, TokenDisplay, TokenFlags, } from "./scanner.js";
|
|
6
6
|
import { IdentifierKind, SyntaxKind, } from "./types.js";
|
|
7
7
|
/**
|
|
8
8
|
* The fixed set of options for each of the kinds of delimited lists in TypeSpec.
|
|
@@ -122,18 +122,6 @@ var ListKind;
|
|
|
122
122
|
close: Token.CloseParen,
|
|
123
123
|
invalidAnnotationTarget: "expression",
|
|
124
124
|
};
|
|
125
|
-
ListKind.ProjectionExpression = {
|
|
126
|
-
...ExpresionsBase,
|
|
127
|
-
allowEmpty: true,
|
|
128
|
-
open: Token.OpenParen,
|
|
129
|
-
close: Token.CloseParen,
|
|
130
|
-
};
|
|
131
|
-
ListKind.ProjectionParameter = {
|
|
132
|
-
...ExpresionsBase,
|
|
133
|
-
allowEmpty: true,
|
|
134
|
-
open: Token.OpenParen,
|
|
135
|
-
close: Token.CloseParen,
|
|
136
|
-
};
|
|
137
125
|
})(ListKind || (ListKind = {}));
|
|
138
126
|
export function parse(code, options = {}) {
|
|
139
127
|
const parser = createParser(code, options);
|
|
@@ -266,10 +254,6 @@ function createParser(code, options = {}) {
|
|
|
266
254
|
reportInvalidDecorators(decorators, "using statement");
|
|
267
255
|
item = parseUsingStatement(pos);
|
|
268
256
|
break;
|
|
269
|
-
case Token.ProjectionKeyword:
|
|
270
|
-
reportInvalidDecorators(decorators, "projection statement");
|
|
271
|
-
item = parseProjectionStatement(pos);
|
|
272
|
-
break;
|
|
273
257
|
case Token.Semicolon:
|
|
274
258
|
reportInvalidDecorators(decorators, "empty statement");
|
|
275
259
|
item = parseEmptyStatement(pos);
|
|
@@ -370,10 +354,6 @@ function createParser(code, options = {}) {
|
|
|
370
354
|
case Token.DecKeyword:
|
|
371
355
|
item = parseDeclaration(pos);
|
|
372
356
|
break;
|
|
373
|
-
case Token.ProjectionKeyword:
|
|
374
|
-
reportInvalidDecorators(decorators, "project statement");
|
|
375
|
-
item = parseProjectionStatement(pos);
|
|
376
|
-
break;
|
|
377
357
|
case Token.EndOfFile:
|
|
378
358
|
parseExpected(Token.CloseBrace);
|
|
379
359
|
return stmts;
|
|
@@ -500,8 +480,28 @@ function createParser(code, options = {}) {
|
|
|
500
480
|
...finishNode(pos),
|
|
501
481
|
};
|
|
502
482
|
}
|
|
483
|
+
function parseIdOrValueForVariant() {
|
|
484
|
+
const nextToken = token();
|
|
485
|
+
let id;
|
|
486
|
+
if (isReservedKeyword(nextToken)) {
|
|
487
|
+
id = parseIdentifier({ allowReservedIdentifier: true });
|
|
488
|
+
// If the next token is not a colon this means we tried to use the reserved keyword as a type reference
|
|
489
|
+
if (token() !== Token.Colon) {
|
|
490
|
+
error({ code: "reserved-identifier", messageId: "future", format: { name: id.sv } });
|
|
491
|
+
}
|
|
492
|
+
return {
|
|
493
|
+
kind: SyntaxKind.TypeReference,
|
|
494
|
+
target: id,
|
|
495
|
+
arguments: [],
|
|
496
|
+
...finishNode(id.pos),
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
else {
|
|
500
|
+
return parseExpression();
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
503
|
function parseUnionVariant(pos, decorators) {
|
|
504
|
-
const idOrExpr =
|
|
504
|
+
const idOrExpr = parseIdOrValueForVariant();
|
|
505
505
|
if (parseOptional(Token.Colon)) {
|
|
506
506
|
let id = undefined;
|
|
507
507
|
if (idOrExpr.kind !== SyntaxKind.TypeReference &&
|
|
@@ -544,7 +544,7 @@ function createParser(code, options = {}) {
|
|
|
544
544
|
}
|
|
545
545
|
function parseUsingStatement(pos) {
|
|
546
546
|
parseExpected(Token.UsingKeyword);
|
|
547
|
-
const name = parseIdentifierOrMemberExpression(
|
|
547
|
+
const name = parseIdentifierOrMemberExpression();
|
|
548
548
|
parseExpected(Token.Semicolon);
|
|
549
549
|
return {
|
|
550
550
|
kind: SyntaxKind.UsingStatement,
|
|
@@ -724,6 +724,7 @@ function createParser(code, options = {}) {
|
|
|
724
724
|
const id = parseIdentifier({
|
|
725
725
|
message: "property",
|
|
726
726
|
allowStringLiteral: true,
|
|
727
|
+
allowReservedIdentifier: true,
|
|
727
728
|
});
|
|
728
729
|
const optional = parseOptional(Token.Question);
|
|
729
730
|
parseExpected(Token.Colon);
|
|
@@ -759,6 +760,7 @@ function createParser(code, options = {}) {
|
|
|
759
760
|
function parseObjectLiteralProperty(pos) {
|
|
760
761
|
const id = parseIdentifier({
|
|
761
762
|
message: "property",
|
|
763
|
+
allowReservedIdentifier: true,
|
|
762
764
|
});
|
|
763
765
|
parseExpected(Token.Colon);
|
|
764
766
|
const value = parseExpression();
|
|
@@ -845,6 +847,7 @@ function createParser(code, options = {}) {
|
|
|
845
847
|
const id = parseIdentifier({
|
|
846
848
|
message: "enumMember",
|
|
847
849
|
allowStringLiteral: true,
|
|
850
|
+
allowReservedIdentifier: true,
|
|
848
851
|
});
|
|
849
852
|
let value;
|
|
850
853
|
if (parseOptional(Token.Colon)) {
|
|
@@ -1012,12 +1015,18 @@ function createParser(code, options = {}) {
|
|
|
1012
1015
|
}
|
|
1013
1016
|
function parseReferenceExpression(message) {
|
|
1014
1017
|
const pos = tokenPos();
|
|
1015
|
-
const target = parseIdentifierOrMemberExpression(
|
|
1018
|
+
const target = parseIdentifierOrMemberExpression({
|
|
1019
|
+
message,
|
|
1020
|
+
allowReservedIdentifierInMember: true,
|
|
1021
|
+
});
|
|
1016
1022
|
return parseReferenceExpressionInternal(target, pos);
|
|
1017
1023
|
}
|
|
1018
1024
|
function parseCallOrReferenceExpression(message) {
|
|
1019
1025
|
const pos = tokenPos();
|
|
1020
|
-
const target = parseIdentifierOrMemberExpression(
|
|
1026
|
+
const target = parseIdentifierOrMemberExpression({
|
|
1027
|
+
message,
|
|
1028
|
+
allowReservedIdentifierInMember: true,
|
|
1029
|
+
});
|
|
1021
1030
|
if (token() === Token.OpenParen) {
|
|
1022
1031
|
const { items: args } = parseList(ListKind.FunctionArguments, parseExpression);
|
|
1023
1032
|
return {
|
|
@@ -1080,7 +1089,7 @@ function createParser(code, options = {}) {
|
|
|
1080
1089
|
// identifier. We want to parse `@ model Foo` as invalid decorator
|
|
1081
1090
|
// `@<missing identifier>` applied to `model Foo`, and not as `@model`
|
|
1082
1091
|
// applied to invalid statement `Foo`.
|
|
1083
|
-
const target = parseIdentifierOrMemberExpression(
|
|
1092
|
+
const target = parseIdentifierOrMemberExpression({ allowReservedIdentifierInMember: true });
|
|
1084
1093
|
const { items: args } = parseOptionalList(ListKind.DecoratorArguments, parseExpression);
|
|
1085
1094
|
if (args.length === 0) {
|
|
1086
1095
|
error({ code: "augment-decorator-target" });
|
|
@@ -1136,7 +1145,10 @@ function createParser(code, options = {}) {
|
|
|
1136
1145
|
// identifier. We want to parse `@ model Foo` as invalid decorator
|
|
1137
1146
|
// `@<missing identifier>` applied to `model Foo`, and not as `@model`
|
|
1138
1147
|
// applied to invalid statement `Foo`.
|
|
1139
|
-
const target = parseIdentifierOrMemberExpression(
|
|
1148
|
+
const target = parseIdentifierOrMemberExpression({
|
|
1149
|
+
allowReservedIdentifier: true,
|
|
1150
|
+
allowReservedIdentifierInMember: true,
|
|
1151
|
+
});
|
|
1140
1152
|
const { items: args } = parseOptionalList(ListKind.DecoratorArguments, parseExpression);
|
|
1141
1153
|
return {
|
|
1142
1154
|
kind: SyntaxKind.DecoratorExpression,
|
|
@@ -1197,11 +1209,11 @@ function createParser(code, options = {}) {
|
|
|
1197
1209
|
return undefined;
|
|
1198
1210
|
}
|
|
1199
1211
|
}
|
|
1200
|
-
function parseIdentifierOrMemberExpression(
|
|
1212
|
+
function parseIdentifierOrMemberExpression(options) {
|
|
1201
1213
|
const pos = tokenPos();
|
|
1202
1214
|
let base = parseIdentifier({
|
|
1203
|
-
message,
|
|
1204
|
-
|
|
1215
|
+
message: options?.message,
|
|
1216
|
+
allowReservedIdentifier: options?.allowReservedIdentifier,
|
|
1205
1217
|
});
|
|
1206
1218
|
while (token() !== Token.EndOfFile) {
|
|
1207
1219
|
if (parseOptional(Token.Dot)) {
|
|
@@ -1214,7 +1226,7 @@ function createParser(code, options = {}) {
|
|
|
1214
1226
|
// `@Outer.model` applied to invalid statement `M {}` instead of
|
|
1215
1227
|
// having incomplete decorator `@Outer.` applied to `model M {}`.
|
|
1216
1228
|
id: parseIdentifier({
|
|
1217
|
-
|
|
1229
|
+
allowReservedIdentifier: options?.allowReservedIdentifierInMember,
|
|
1218
1230
|
}),
|
|
1219
1231
|
selector: ".",
|
|
1220
1232
|
...finishNode(pos),
|
|
@@ -1474,8 +1486,14 @@ function createParser(code, options = {}) {
|
|
|
1474
1486
|
};
|
|
1475
1487
|
}
|
|
1476
1488
|
function parseIdentifier(options) {
|
|
1477
|
-
if (
|
|
1489
|
+
if (isKeyword(token())) {
|
|
1478
1490
|
error({ code: "reserved-identifier" });
|
|
1491
|
+
return createMissingIdentifier();
|
|
1492
|
+
}
|
|
1493
|
+
else if (isReservedKeyword(token())) {
|
|
1494
|
+
if (!options?.allowReservedIdentifier) {
|
|
1495
|
+
error({ code: "reserved-identifier", messageId: "future", format: { name: tokenValue() } });
|
|
1496
|
+
}
|
|
1479
1497
|
}
|
|
1480
1498
|
else if (token() !== Token.Identifier &&
|
|
1481
1499
|
(!options?.allowStringLiteral || token() !== Token.StringLiteral)) {
|
|
@@ -1619,570 +1637,6 @@ function createParser(code, options = {}) {
|
|
|
1619
1637
|
}
|
|
1620
1638
|
return flags;
|
|
1621
1639
|
}
|
|
1622
|
-
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
1623
|
-
function parseProjectionStatement(pos) {
|
|
1624
|
-
parseExpected(Token.ProjectionKeyword);
|
|
1625
|
-
const selector = parseProjectionSelector();
|
|
1626
|
-
parseExpected(Token.Hash);
|
|
1627
|
-
const id = parseIdentifier();
|
|
1628
|
-
parseExpected(Token.OpenBrace);
|
|
1629
|
-
const projectionMap = new Map();
|
|
1630
|
-
const projections = [];
|
|
1631
|
-
while (token() === Token.Identifier) {
|
|
1632
|
-
const projection = parseProjection();
|
|
1633
|
-
if (projection.direction !== "<error>") {
|
|
1634
|
-
if (projectionMap.has(projection.direction)) {
|
|
1635
|
-
error({ code: "duplicate-symbol", target: projection, format: { name: "projection" } });
|
|
1636
|
-
}
|
|
1637
|
-
else {
|
|
1638
|
-
projectionMap.set(projection.direction, projection);
|
|
1639
|
-
}
|
|
1640
|
-
}
|
|
1641
|
-
// NOTE: Don't drop projections with error in direction definition from the AST.
|
|
1642
|
-
projections.push(projection);
|
|
1643
|
-
}
|
|
1644
|
-
parseExpected(Token.CloseBrace);
|
|
1645
|
-
return {
|
|
1646
|
-
kind: SyntaxKind.ProjectionStatement,
|
|
1647
|
-
selector,
|
|
1648
|
-
projections,
|
|
1649
|
-
preTo: projectionMap.get("pre_to"),
|
|
1650
|
-
preFrom: projectionMap.get("pre_from"),
|
|
1651
|
-
from: projectionMap.get("from"),
|
|
1652
|
-
to: projectionMap.get("to"),
|
|
1653
|
-
id,
|
|
1654
|
-
...finishNode(pos),
|
|
1655
|
-
};
|
|
1656
|
-
}
|
|
1657
|
-
function parseProjection() {
|
|
1658
|
-
const pos = tokenPos();
|
|
1659
|
-
let directionId = parseIdentifier({ message: "projectionDirection" });
|
|
1660
|
-
let direction;
|
|
1661
|
-
const modifierIds = [];
|
|
1662
|
-
let isPre = false;
|
|
1663
|
-
if (directionId.sv === "pre") {
|
|
1664
|
-
isPre = true;
|
|
1665
|
-
modifierIds.push(directionId);
|
|
1666
|
-
directionId = parseIdentifier({ message: "projectionDirection" });
|
|
1667
|
-
}
|
|
1668
|
-
if (directionId.sv !== "to" && directionId.sv !== "from") {
|
|
1669
|
-
error({ code: "token-expected", messageId: "projectionDirection" });
|
|
1670
|
-
direction = "<error>";
|
|
1671
|
-
}
|
|
1672
|
-
else if (isPre) {
|
|
1673
|
-
direction = directionId.sv === "to" ? "pre_to" : "pre_from";
|
|
1674
|
-
}
|
|
1675
|
-
else {
|
|
1676
|
-
direction = directionId.sv;
|
|
1677
|
-
}
|
|
1678
|
-
let parameters;
|
|
1679
|
-
if (token() === Token.OpenParen) {
|
|
1680
|
-
parameters = parseList(ListKind.ProjectionParameter, parseProjectionParameter).items;
|
|
1681
|
-
}
|
|
1682
|
-
else {
|
|
1683
|
-
parameters = [];
|
|
1684
|
-
}
|
|
1685
|
-
parseExpected(Token.OpenBrace);
|
|
1686
|
-
const body = parseProjectionStatementList();
|
|
1687
|
-
parseExpected(Token.CloseBrace);
|
|
1688
|
-
return {
|
|
1689
|
-
kind: SyntaxKind.Projection,
|
|
1690
|
-
body,
|
|
1691
|
-
direction,
|
|
1692
|
-
directionId,
|
|
1693
|
-
modifierIds,
|
|
1694
|
-
parameters,
|
|
1695
|
-
...finishNode(pos),
|
|
1696
|
-
};
|
|
1697
|
-
}
|
|
1698
|
-
function parseProjectionParameter() {
|
|
1699
|
-
const pos = tokenPos();
|
|
1700
|
-
const id = parseIdentifier();
|
|
1701
|
-
return {
|
|
1702
|
-
kind: SyntaxKind.ProjectionParameterDeclaration,
|
|
1703
|
-
id,
|
|
1704
|
-
...finishNode(pos),
|
|
1705
|
-
};
|
|
1706
|
-
}
|
|
1707
|
-
function parseProjectionStatementList() {
|
|
1708
|
-
const stmts = [];
|
|
1709
|
-
while (token() !== Token.CloseBrace) {
|
|
1710
|
-
const startPos = tokenPos();
|
|
1711
|
-
if (token() === Token.EndOfFile) {
|
|
1712
|
-
error({ code: "token-expected", messageId: "default", format: { token: "}" } });
|
|
1713
|
-
break;
|
|
1714
|
-
}
|
|
1715
|
-
const expr = parseProjectionExpressionStatement();
|
|
1716
|
-
stmts.push(expr);
|
|
1717
|
-
if (tokenPos() === startPos) {
|
|
1718
|
-
// we didn't manage to parse anything, so break out
|
|
1719
|
-
// and we'll report errors elsewhere.
|
|
1720
|
-
break;
|
|
1721
|
-
}
|
|
1722
|
-
}
|
|
1723
|
-
return stmts;
|
|
1724
|
-
}
|
|
1725
|
-
function parseProjectionExpressionStatement() {
|
|
1726
|
-
const pos = tokenPos();
|
|
1727
|
-
const expr = parseProjectionExpression();
|
|
1728
|
-
parseExpected(Token.Semicolon);
|
|
1729
|
-
return {
|
|
1730
|
-
kind: SyntaxKind.ProjectionExpressionStatement,
|
|
1731
|
-
expr,
|
|
1732
|
-
...finishNode(pos),
|
|
1733
|
-
};
|
|
1734
|
-
}
|
|
1735
|
-
function parseProjectionExpression() {
|
|
1736
|
-
return parseProjectionReturnExpressionOrHigher();
|
|
1737
|
-
}
|
|
1738
|
-
function parseProjectionReturnExpressionOrHigher() {
|
|
1739
|
-
if (token() === Token.ReturnKeyword) {
|
|
1740
|
-
const pos = tokenPos();
|
|
1741
|
-
parseExpected(Token.ReturnKeyword);
|
|
1742
|
-
return {
|
|
1743
|
-
kind: SyntaxKind.Return,
|
|
1744
|
-
value: parseProjectionExpression(),
|
|
1745
|
-
...finishNode(pos),
|
|
1746
|
-
};
|
|
1747
|
-
}
|
|
1748
|
-
return parseProjectionLogicalOrExpressionOrHigher();
|
|
1749
|
-
}
|
|
1750
|
-
function parseProjectionLogicalOrExpressionOrHigher() {
|
|
1751
|
-
let expr = parseProjectionLogicalAndExpressionOrHigher();
|
|
1752
|
-
while (token() !== Token.EndOfFile) {
|
|
1753
|
-
const pos = expr.pos;
|
|
1754
|
-
if (parseOptional(Token.BarBar)) {
|
|
1755
|
-
expr = {
|
|
1756
|
-
kind: SyntaxKind.ProjectionLogicalExpression,
|
|
1757
|
-
op: "||",
|
|
1758
|
-
left: expr,
|
|
1759
|
-
right: parseProjectionLogicalAndExpressionOrHigher(),
|
|
1760
|
-
...finishNode(pos),
|
|
1761
|
-
};
|
|
1762
|
-
}
|
|
1763
|
-
else {
|
|
1764
|
-
break;
|
|
1765
|
-
}
|
|
1766
|
-
}
|
|
1767
|
-
return expr;
|
|
1768
|
-
}
|
|
1769
|
-
function parseProjectionLogicalAndExpressionOrHigher() {
|
|
1770
|
-
let expr = parseProjectionEqualityExpressionOrHigher();
|
|
1771
|
-
while (token() !== Token.EndOfFile) {
|
|
1772
|
-
const pos = expr.pos;
|
|
1773
|
-
if (parseOptional(Token.AmpsersandAmpersand)) {
|
|
1774
|
-
expr = {
|
|
1775
|
-
kind: SyntaxKind.ProjectionLogicalExpression,
|
|
1776
|
-
op: "&&",
|
|
1777
|
-
left: expr,
|
|
1778
|
-
right: parseProjectionEqualityExpressionOrHigher(),
|
|
1779
|
-
...finishNode(pos),
|
|
1780
|
-
};
|
|
1781
|
-
}
|
|
1782
|
-
else {
|
|
1783
|
-
break;
|
|
1784
|
-
}
|
|
1785
|
-
}
|
|
1786
|
-
return expr;
|
|
1787
|
-
}
|
|
1788
|
-
function parseProjectionEqualityExpressionOrHigher() {
|
|
1789
|
-
let expr = parseProjectionRelationalExpressionOrHigher();
|
|
1790
|
-
while (token() !== Token.EndOfFile) {
|
|
1791
|
-
const pos = expr.pos;
|
|
1792
|
-
const tok = token();
|
|
1793
|
-
if (tok === Token.EqualsEquals || tok === Token.ExclamationEquals) {
|
|
1794
|
-
const op = tokenValue();
|
|
1795
|
-
nextToken();
|
|
1796
|
-
expr = {
|
|
1797
|
-
kind: SyntaxKind.ProjectionEqualityExpression,
|
|
1798
|
-
op,
|
|
1799
|
-
left: expr,
|
|
1800
|
-
right: parseProjectionRelationalExpressionOrHigher(),
|
|
1801
|
-
...finishNode(pos),
|
|
1802
|
-
};
|
|
1803
|
-
}
|
|
1804
|
-
else {
|
|
1805
|
-
break;
|
|
1806
|
-
}
|
|
1807
|
-
}
|
|
1808
|
-
return expr;
|
|
1809
|
-
}
|
|
1810
|
-
function parseProjectionRelationalExpressionOrHigher() {
|
|
1811
|
-
let expr = parseProjectionAdditiveExpressionOrHigher();
|
|
1812
|
-
while (token() !== Token.EndOfFile) {
|
|
1813
|
-
const pos = expr.pos;
|
|
1814
|
-
const tok = token();
|
|
1815
|
-
if (tok === Token.LessThan ||
|
|
1816
|
-
tok === Token.LessThanEquals ||
|
|
1817
|
-
tok === Token.GreaterThan ||
|
|
1818
|
-
tok === Token.GreaterThanEquals) {
|
|
1819
|
-
const op = tokenValue();
|
|
1820
|
-
nextToken();
|
|
1821
|
-
expr = {
|
|
1822
|
-
kind: SyntaxKind.ProjectionRelationalExpression,
|
|
1823
|
-
op,
|
|
1824
|
-
left: expr,
|
|
1825
|
-
right: parseProjectionAdditiveExpressionOrHigher(),
|
|
1826
|
-
...finishNode(pos),
|
|
1827
|
-
};
|
|
1828
|
-
}
|
|
1829
|
-
else {
|
|
1830
|
-
break;
|
|
1831
|
-
}
|
|
1832
|
-
}
|
|
1833
|
-
return expr;
|
|
1834
|
-
}
|
|
1835
|
-
function parseProjectionAdditiveExpressionOrHigher() {
|
|
1836
|
-
let expr = parseProjectionMultiplicativeExpressionOrHigher();
|
|
1837
|
-
while (token() !== Token.EndOfFile) {
|
|
1838
|
-
const pos = expr.pos;
|
|
1839
|
-
const tok = token();
|
|
1840
|
-
if (tok === Token.Plus || tok === Token.Hyphen) {
|
|
1841
|
-
const op = tokenValue();
|
|
1842
|
-
nextToken();
|
|
1843
|
-
expr = {
|
|
1844
|
-
kind: SyntaxKind.ProjectionArithmeticExpression,
|
|
1845
|
-
op,
|
|
1846
|
-
left: expr,
|
|
1847
|
-
right: parseProjectionMultiplicativeExpressionOrHigher(),
|
|
1848
|
-
...finishNode(pos),
|
|
1849
|
-
};
|
|
1850
|
-
}
|
|
1851
|
-
else {
|
|
1852
|
-
break;
|
|
1853
|
-
}
|
|
1854
|
-
}
|
|
1855
|
-
return expr;
|
|
1856
|
-
}
|
|
1857
|
-
function parseProjectionMultiplicativeExpressionOrHigher() {
|
|
1858
|
-
let expr = parseProjectionUnaryExpressionOrHigher();
|
|
1859
|
-
while (token() !== Token.EndOfFile) {
|
|
1860
|
-
const pos = expr.pos;
|
|
1861
|
-
const tok = token();
|
|
1862
|
-
if (tok === Token.ForwardSlash || tok === Token.Star) {
|
|
1863
|
-
const op = tokenValue();
|
|
1864
|
-
nextToken();
|
|
1865
|
-
expr = {
|
|
1866
|
-
kind: SyntaxKind.ProjectionArithmeticExpression,
|
|
1867
|
-
op,
|
|
1868
|
-
left: expr,
|
|
1869
|
-
right: parseProjectionUnaryExpressionOrHigher(),
|
|
1870
|
-
...finishNode(pos),
|
|
1871
|
-
};
|
|
1872
|
-
}
|
|
1873
|
-
else {
|
|
1874
|
-
break;
|
|
1875
|
-
}
|
|
1876
|
-
}
|
|
1877
|
-
return expr;
|
|
1878
|
-
}
|
|
1879
|
-
function parseProjectionUnaryExpressionOrHigher() {
|
|
1880
|
-
if (token() === Token.Exclamation) {
|
|
1881
|
-
const pos = tokenPos();
|
|
1882
|
-
nextToken();
|
|
1883
|
-
return {
|
|
1884
|
-
kind: SyntaxKind.ProjectionUnaryExpression,
|
|
1885
|
-
op: "!",
|
|
1886
|
-
target: parseProjectionUnaryExpressionOrHigher(),
|
|
1887
|
-
...finishNode(pos),
|
|
1888
|
-
};
|
|
1889
|
-
}
|
|
1890
|
-
return parseProjectionCallExpressionOrHigher();
|
|
1891
|
-
}
|
|
1892
|
-
function parseProjectionCallExpressionOrHigher() {
|
|
1893
|
-
let expr = parseProjectionDecoratorReferenceExpressionOrHigher();
|
|
1894
|
-
while (token() !== Token.EndOfFile) {
|
|
1895
|
-
const pos = expr.pos;
|
|
1896
|
-
expr = parseProjectionMemberExpressionRest(expr, pos);
|
|
1897
|
-
if (token() === Token.OpenParen) {
|
|
1898
|
-
expr = {
|
|
1899
|
-
kind: SyntaxKind.ProjectionCallExpression,
|
|
1900
|
-
callKind: "method",
|
|
1901
|
-
target: expr,
|
|
1902
|
-
arguments: parseList(ListKind.CallArguments, parseProjectionExpression).items,
|
|
1903
|
-
...finishNode(pos),
|
|
1904
|
-
};
|
|
1905
|
-
}
|
|
1906
|
-
else {
|
|
1907
|
-
break;
|
|
1908
|
-
}
|
|
1909
|
-
}
|
|
1910
|
-
return expr;
|
|
1911
|
-
}
|
|
1912
|
-
function parseProjectionDecoratorReferenceExpressionOrHigher() {
|
|
1913
|
-
if (token() === Token.At) {
|
|
1914
|
-
const pos = tokenPos();
|
|
1915
|
-
nextToken();
|
|
1916
|
-
return {
|
|
1917
|
-
kind: SyntaxKind.ProjectionDecoratorReferenceExpression,
|
|
1918
|
-
target: parseIdentifierOrMemberExpression(undefined, true),
|
|
1919
|
-
...finishNode(pos),
|
|
1920
|
-
};
|
|
1921
|
-
}
|
|
1922
|
-
return parseProjectionMemberExpressionOrHigher();
|
|
1923
|
-
}
|
|
1924
|
-
function parseProjectionMemberExpressionOrHigher() {
|
|
1925
|
-
const pos = tokenPos();
|
|
1926
|
-
let expr = parseProjectionPrimaryExpression();
|
|
1927
|
-
expr = parseProjectionMemberExpressionRest(expr, pos);
|
|
1928
|
-
return expr;
|
|
1929
|
-
}
|
|
1930
|
-
function parseProjectionMemberExpressionRest(expr, pos) {
|
|
1931
|
-
while (token() !== Token.EndOfFile) {
|
|
1932
|
-
if (parseOptional(Token.Dot)) {
|
|
1933
|
-
expr = {
|
|
1934
|
-
kind: SyntaxKind.ProjectionMemberExpression,
|
|
1935
|
-
base: expr,
|
|
1936
|
-
id: parseIdentifier(),
|
|
1937
|
-
selector: ".",
|
|
1938
|
-
...finishNode(pos),
|
|
1939
|
-
};
|
|
1940
|
-
}
|
|
1941
|
-
else if (parseOptional(Token.ColonColon)) {
|
|
1942
|
-
expr = {
|
|
1943
|
-
kind: SyntaxKind.ProjectionMemberExpression,
|
|
1944
|
-
base: expr,
|
|
1945
|
-
id: parseIdentifier(),
|
|
1946
|
-
selector: "::",
|
|
1947
|
-
...finishNode(pos),
|
|
1948
|
-
};
|
|
1949
|
-
}
|
|
1950
|
-
else {
|
|
1951
|
-
break;
|
|
1952
|
-
}
|
|
1953
|
-
}
|
|
1954
|
-
return expr;
|
|
1955
|
-
}
|
|
1956
|
-
function parseProjectionPrimaryExpression() {
|
|
1957
|
-
switch (token()) {
|
|
1958
|
-
case Token.IfKeyword:
|
|
1959
|
-
return parseProjectionIfExpression();
|
|
1960
|
-
case Token.NumericLiteral:
|
|
1961
|
-
return parseNumericLiteral();
|
|
1962
|
-
case Token.StringLiteral:
|
|
1963
|
-
return parseStringLiteral();
|
|
1964
|
-
case Token.TrueKeyword:
|
|
1965
|
-
case Token.FalseKeyword:
|
|
1966
|
-
return parseBooleanLiteral();
|
|
1967
|
-
case Token.OpenBracket:
|
|
1968
|
-
return parseProjectionTupleExpression();
|
|
1969
|
-
case Token.OpenBrace:
|
|
1970
|
-
return parseProjectionModelExpression();
|
|
1971
|
-
case Token.OpenParen:
|
|
1972
|
-
return parseProjectionLambdaOrParenthesizedExpression();
|
|
1973
|
-
case Token.VoidKeyword:
|
|
1974
|
-
return parseVoidKeyword();
|
|
1975
|
-
case Token.NeverKeyword:
|
|
1976
|
-
return parseNeverKeyword();
|
|
1977
|
-
case Token.UnknownKeyword:
|
|
1978
|
-
return parseUnknownKeyword();
|
|
1979
|
-
default:
|
|
1980
|
-
return parseIdentifier({ message: "expression" });
|
|
1981
|
-
}
|
|
1982
|
-
}
|
|
1983
|
-
function parseProjectionLambdaOrParenthesizedExpression() {
|
|
1984
|
-
const pos = tokenPos();
|
|
1985
|
-
const exprs = parseList(ListKind.ProjectionExpression, parseProjectionExpression).items;
|
|
1986
|
-
if (token() === Token.EqualsGreaterThan) {
|
|
1987
|
-
// unpack the exprs (which should be just identifiers) into a param list
|
|
1988
|
-
const params = [];
|
|
1989
|
-
for (const expr of exprs) {
|
|
1990
|
-
if (expr.kind === SyntaxKind.Identifier) {
|
|
1991
|
-
params.push(withSymbol({
|
|
1992
|
-
kind: SyntaxKind.ProjectionLambdaParameterDeclaration,
|
|
1993
|
-
id: expr,
|
|
1994
|
-
pos: expr.pos,
|
|
1995
|
-
end: expr.end,
|
|
1996
|
-
flags: 0 /* NodeFlags.None */,
|
|
1997
|
-
}));
|
|
1998
|
-
}
|
|
1999
|
-
else {
|
|
2000
|
-
error({ code: "token-expected", messageId: "identifier", target: expr });
|
|
2001
|
-
}
|
|
2002
|
-
}
|
|
2003
|
-
return parseProjectionLambdaExpressionRest(pos, params);
|
|
2004
|
-
}
|
|
2005
|
-
else {
|
|
2006
|
-
if (exprs.length === 0) {
|
|
2007
|
-
error({
|
|
2008
|
-
code: "token-expected",
|
|
2009
|
-
messageId: "expression",
|
|
2010
|
-
});
|
|
2011
|
-
}
|
|
2012
|
-
// verify we only have one entry
|
|
2013
|
-
for (let i = 1; i < exprs.length; i++) {
|
|
2014
|
-
error({
|
|
2015
|
-
code: "token-expected",
|
|
2016
|
-
messageId: "unexpected",
|
|
2017
|
-
format: { token: "expression" },
|
|
2018
|
-
target: exprs[i],
|
|
2019
|
-
});
|
|
2020
|
-
}
|
|
2021
|
-
return exprs[0];
|
|
2022
|
-
}
|
|
2023
|
-
}
|
|
2024
|
-
function parseProjectionLambdaExpressionRest(pos, parameters) {
|
|
2025
|
-
parseExpected(Token.EqualsGreaterThan);
|
|
2026
|
-
const body = parseProjectionBlockExpression();
|
|
2027
|
-
return {
|
|
2028
|
-
kind: SyntaxKind.ProjectionLambdaExpression,
|
|
2029
|
-
parameters,
|
|
2030
|
-
body,
|
|
2031
|
-
...finishNode(pos),
|
|
2032
|
-
};
|
|
2033
|
-
}
|
|
2034
|
-
function parseProjectionModelExpression() {
|
|
2035
|
-
const pos = tokenPos();
|
|
2036
|
-
const { items: properties } = parseList(ListKind.ModelProperties, parseProjectionModelPropertyOrSpread);
|
|
2037
|
-
return {
|
|
2038
|
-
kind: SyntaxKind.ProjectionModelExpression,
|
|
2039
|
-
properties,
|
|
2040
|
-
...finishNode(pos),
|
|
2041
|
-
};
|
|
2042
|
-
}
|
|
2043
|
-
function parseProjectionModelPropertyOrSpread(pos, decorators) {
|
|
2044
|
-
return token() === Token.Ellipsis
|
|
2045
|
-
? parseProjectionModelSpreadProperty(pos, decorators)
|
|
2046
|
-
: parseProjectionModelProperty(pos, decorators);
|
|
2047
|
-
}
|
|
2048
|
-
function parseProjectionModelSpreadProperty(pos, decorators) {
|
|
2049
|
-
parseExpected(Token.Ellipsis);
|
|
2050
|
-
reportInvalidDecorators(decorators, "spread property");
|
|
2051
|
-
const target = parseProjectionExpression();
|
|
2052
|
-
return {
|
|
2053
|
-
kind: SyntaxKind.ProjectionModelSpreadProperty,
|
|
2054
|
-
target,
|
|
2055
|
-
...finishNode(pos),
|
|
2056
|
-
};
|
|
2057
|
-
}
|
|
2058
|
-
function parseProjectionModelProperty(pos, decorators) {
|
|
2059
|
-
const id = parseIdentifier({ message: "property", allowStringLiteral: true });
|
|
2060
|
-
const optional = parseOptional(Token.Question);
|
|
2061
|
-
parseExpected(Token.Colon);
|
|
2062
|
-
const value = parseProjectionExpression();
|
|
2063
|
-
const hasDefault = parseOptional(Token.Equals);
|
|
2064
|
-
const defaultValue = hasDefault ? parseProjectionExpression() : undefined;
|
|
2065
|
-
return {
|
|
2066
|
-
kind: SyntaxKind.ProjectionModelProperty,
|
|
2067
|
-
id,
|
|
2068
|
-
decorators,
|
|
2069
|
-
value,
|
|
2070
|
-
optional,
|
|
2071
|
-
default: defaultValue,
|
|
2072
|
-
...finishNode(pos),
|
|
2073
|
-
};
|
|
2074
|
-
}
|
|
2075
|
-
function parseProjectionIfExpression() {
|
|
2076
|
-
const pos = tokenPos();
|
|
2077
|
-
parseExpected(Token.IfKeyword);
|
|
2078
|
-
const test = parseProjectionExpression();
|
|
2079
|
-
const consequent = parseProjectionBlockExpression();
|
|
2080
|
-
let alternate = undefined;
|
|
2081
|
-
if (parseOptional(Token.ElseKeyword)) {
|
|
2082
|
-
if (token() === Token.IfKeyword) {
|
|
2083
|
-
alternate = parseProjectionIfExpression();
|
|
2084
|
-
}
|
|
2085
|
-
else {
|
|
2086
|
-
alternate = parseProjectionBlockExpression();
|
|
2087
|
-
}
|
|
2088
|
-
}
|
|
2089
|
-
return {
|
|
2090
|
-
kind: SyntaxKind.ProjectionIfExpression,
|
|
2091
|
-
test,
|
|
2092
|
-
consequent,
|
|
2093
|
-
alternate,
|
|
2094
|
-
...finishNode(pos),
|
|
2095
|
-
};
|
|
2096
|
-
}
|
|
2097
|
-
function parseProjectionBlockExpression() {
|
|
2098
|
-
const pos = tokenPos();
|
|
2099
|
-
parseExpected(Token.OpenBrace);
|
|
2100
|
-
const statements = parseProjectionStatementList();
|
|
2101
|
-
parseExpected(Token.CloseBrace);
|
|
2102
|
-
return {
|
|
2103
|
-
kind: SyntaxKind.ProjectionBlockExpression,
|
|
2104
|
-
statements,
|
|
2105
|
-
...finishNode(pos),
|
|
2106
|
-
};
|
|
2107
|
-
}
|
|
2108
|
-
function parseProjectionTupleExpression() {
|
|
2109
|
-
const pos = tokenPos();
|
|
2110
|
-
const { items: values } = parseList(ListKind.Tuple, parseProjectionExpression);
|
|
2111
|
-
return {
|
|
2112
|
-
kind: SyntaxKind.ProjectionTupleExpression,
|
|
2113
|
-
values,
|
|
2114
|
-
...finishNode(pos),
|
|
2115
|
-
};
|
|
2116
|
-
}
|
|
2117
|
-
function parseProjectionSelector() {
|
|
2118
|
-
const pos = tokenPos();
|
|
2119
|
-
const selectorTok = expectTokenIsOneOf(Token.Identifier, Token.ModelKeyword, Token.OpKeyword, Token.InterfaceKeyword, Token.UnionKeyword, Token.EnumKeyword, Token.ScalarKeyword);
|
|
2120
|
-
switch (selectorTok) {
|
|
2121
|
-
case Token.Identifier:
|
|
2122
|
-
const id = parseIdentifierOrMemberExpression(undefined, true);
|
|
2123
|
-
if (id.kind === SyntaxKind.Identifier) {
|
|
2124
|
-
switch (id.sv) {
|
|
2125
|
-
case "modelproperty":
|
|
2126
|
-
return {
|
|
2127
|
-
kind: SyntaxKind.ProjectionModelPropertySelector,
|
|
2128
|
-
...finishNode(pos),
|
|
2129
|
-
};
|
|
2130
|
-
case "unionvariant":
|
|
2131
|
-
return {
|
|
2132
|
-
kind: SyntaxKind.ProjectionUnionVariantSelector,
|
|
2133
|
-
...finishNode(pos),
|
|
2134
|
-
};
|
|
2135
|
-
case "enummember":
|
|
2136
|
-
return {
|
|
2137
|
-
kind: SyntaxKind.ProjectionEnumMemberSelector,
|
|
2138
|
-
...finishNode(pos),
|
|
2139
|
-
};
|
|
2140
|
-
}
|
|
2141
|
-
}
|
|
2142
|
-
return id;
|
|
2143
|
-
case Token.ModelKeyword:
|
|
2144
|
-
nextToken();
|
|
2145
|
-
return {
|
|
2146
|
-
kind: SyntaxKind.ProjectionModelSelector,
|
|
2147
|
-
...finishNode(pos),
|
|
2148
|
-
};
|
|
2149
|
-
case Token.OpKeyword:
|
|
2150
|
-
nextToken();
|
|
2151
|
-
return {
|
|
2152
|
-
kind: SyntaxKind.ProjectionOperationSelector,
|
|
2153
|
-
...finishNode(pos),
|
|
2154
|
-
};
|
|
2155
|
-
case Token.InterfaceKeyword:
|
|
2156
|
-
nextToken();
|
|
2157
|
-
return {
|
|
2158
|
-
kind: SyntaxKind.ProjectionInterfaceSelector,
|
|
2159
|
-
...finishNode(pos),
|
|
2160
|
-
};
|
|
2161
|
-
case Token.UnionKeyword:
|
|
2162
|
-
nextToken();
|
|
2163
|
-
return {
|
|
2164
|
-
kind: SyntaxKind.ProjectionUnionSelector,
|
|
2165
|
-
...finishNode(pos),
|
|
2166
|
-
};
|
|
2167
|
-
case Token.EnumKeyword:
|
|
2168
|
-
nextToken();
|
|
2169
|
-
return {
|
|
2170
|
-
kind: SyntaxKind.ProjectionEnumSelector,
|
|
2171
|
-
...finishNode(pos),
|
|
2172
|
-
};
|
|
2173
|
-
case Token.ScalarKeyword:
|
|
2174
|
-
nextToken();
|
|
2175
|
-
return {
|
|
2176
|
-
kind: SyntaxKind.ProjectionScalarSelector,
|
|
2177
|
-
...finishNode(pos),
|
|
2178
|
-
};
|
|
2179
|
-
default:
|
|
2180
|
-
// recovery: return a missing identifier to use as the selector
|
|
2181
|
-
// we don't need to emit a diagnostic here as the `expectTokenOneOf` above
|
|
2182
|
-
// will have done so.
|
|
2183
|
-
return createMissingIdentifier();
|
|
2184
|
-
}
|
|
2185
|
-
}
|
|
2186
1640
|
function parseRange(mode, range, callback) {
|
|
2187
1641
|
const savedMode = currentMode;
|
|
2188
1642
|
const result = scanner.scanRange(range, () => {
|
|
@@ -2925,58 +2379,12 @@ export function visitChildren(node, cb) {
|
|
|
2925
2379
|
return visitEach(cb, node.values);
|
|
2926
2380
|
case SyntaxKind.UnionExpression:
|
|
2927
2381
|
return visitEach(cb, node.options);
|
|
2928
|
-
case SyntaxKind.Projection:
|
|
2929
|
-
return (visitNode(cb, node.directionId) ||
|
|
2930
|
-
visitEach(cb, node.modifierIds) ||
|
|
2931
|
-
visitEach(cb, node.parameters) ||
|
|
2932
|
-
visitEach(cb, node.body));
|
|
2933
|
-
case SyntaxKind.ProjectionExpressionStatement:
|
|
2934
|
-
return visitNode(cb, node.expr);
|
|
2935
|
-
case SyntaxKind.ProjectionCallExpression:
|
|
2936
|
-
return visitNode(cb, node.target) || visitEach(cb, node.arguments);
|
|
2937
|
-
case SyntaxKind.ProjectionMemberExpression:
|
|
2938
|
-
return visitNode(cb, node.base) || visitNode(cb, node.id);
|
|
2939
|
-
// binops
|
|
2940
|
-
case SyntaxKind.ProjectionLogicalExpression:
|
|
2941
|
-
case SyntaxKind.ProjectionRelationalExpression:
|
|
2942
|
-
case SyntaxKind.ProjectionArithmeticExpression:
|
|
2943
|
-
case SyntaxKind.ProjectionEqualityExpression:
|
|
2944
|
-
return visitNode(cb, node.left) || visitNode(cb, node.right);
|
|
2945
|
-
case SyntaxKind.ProjectionUnaryExpression:
|
|
2946
|
-
return visitNode(cb, node.target);
|
|
2947
|
-
case SyntaxKind.ProjectionModelExpression:
|
|
2948
|
-
return visitEach(cb, node.properties);
|
|
2949
|
-
case SyntaxKind.ProjectionModelProperty:
|
|
2950
|
-
return (visitEach(cb, node.decorators) ||
|
|
2951
|
-
visitNode(cb, node.id) ||
|
|
2952
|
-
visitNode(cb, node.value) ||
|
|
2953
|
-
visitNode(cb, node.default));
|
|
2954
|
-
case SyntaxKind.ProjectionModelSpreadProperty:
|
|
2955
|
-
return visitNode(cb, node.target);
|
|
2956
|
-
case SyntaxKind.ProjectionTupleExpression:
|
|
2957
|
-
return visitEach(cb, node.values);
|
|
2958
|
-
case SyntaxKind.ProjectionBlockExpression:
|
|
2959
|
-
return visitEach(cb, node.statements);
|
|
2960
|
-
case SyntaxKind.ProjectionIfExpression:
|
|
2961
|
-
return (visitNode(cb, node.test) || visitNode(cb, node.consequent) || visitNode(cb, node.alternate));
|
|
2962
|
-
case SyntaxKind.ProjectionLambdaExpression:
|
|
2963
|
-
return visitEach(cb, node.parameters) || visitNode(cb, node.body);
|
|
2964
|
-
case SyntaxKind.ProjectionStatement:
|
|
2965
|
-
return (visitNode(cb, node.id) || visitNode(cb, node.selector) || visitEach(cb, node.projections));
|
|
2966
|
-
case SyntaxKind.ProjectionDecoratorReferenceExpression:
|
|
2967
|
-
return visitNode(cb, node.target);
|
|
2968
|
-
case SyntaxKind.Return:
|
|
2969
|
-
return visitNode(cb, node.value);
|
|
2970
2382
|
case SyntaxKind.InvalidStatement:
|
|
2971
2383
|
return visitEach(cb, node.decorators);
|
|
2972
2384
|
case SyntaxKind.TemplateParameterDeclaration:
|
|
2973
2385
|
return (visitNode(cb, node.id) || visitNode(cb, node.constraint) || visitNode(cb, node.default));
|
|
2974
2386
|
case SyntaxKind.TemplateArgument:
|
|
2975
2387
|
return (node.name && visitNode(cb, node.name)) || visitNode(cb, node.argument);
|
|
2976
|
-
case SyntaxKind.ProjectionLambdaParameterDeclaration:
|
|
2977
|
-
return visitNode(cb, node.id);
|
|
2978
|
-
case SyntaxKind.ProjectionParameterDeclaration:
|
|
2979
|
-
return visitNode(cb, node.id);
|
|
2980
2388
|
case SyntaxKind.Doc:
|
|
2981
2389
|
return visitEach(cb, node.content) || visitEach(cb, node.tags);
|
|
2982
2390
|
case SyntaxKind.DocParamTag:
|
|
@@ -3009,15 +2417,6 @@ export function visitChildren(node, cb) {
|
|
|
3009
2417
|
case SyntaxKind.BooleanLiteral:
|
|
3010
2418
|
case SyntaxKind.Identifier:
|
|
3011
2419
|
case SyntaxKind.EmptyStatement:
|
|
3012
|
-
case SyntaxKind.ProjectionModelSelector:
|
|
3013
|
-
case SyntaxKind.ProjectionModelPropertySelector:
|
|
3014
|
-
case SyntaxKind.ProjectionScalarSelector:
|
|
3015
|
-
case SyntaxKind.ProjectionUnionSelector:
|
|
3016
|
-
case SyntaxKind.ProjectionUnionVariantSelector:
|
|
3017
|
-
case SyntaxKind.ProjectionInterfaceSelector:
|
|
3018
|
-
case SyntaxKind.ProjectionOperationSelector:
|
|
3019
|
-
case SyntaxKind.ProjectionEnumSelector:
|
|
3020
|
-
case SyntaxKind.ProjectionEnumMemberSelector:
|
|
3021
2420
|
case SyntaxKind.VoidKeyword:
|
|
3022
2421
|
case SyntaxKind.NeverKeyword:
|
|
3023
2422
|
case SyntaxKind.ExternKeyword:
|
|
@@ -3193,9 +2592,6 @@ export function getIdentifierContext(id) {
|
|
|
3193
2592
|
case SyntaxKind.DecoratorExpression:
|
|
3194
2593
|
kind = IdentifierKind.Decorator;
|
|
3195
2594
|
break;
|
|
3196
|
-
case SyntaxKind.ProjectionCallExpression:
|
|
3197
|
-
kind = IdentifierKind.Function;
|
|
3198
|
-
break;
|
|
3199
2595
|
case SyntaxKind.UsingStatement:
|
|
3200
2596
|
kind = IdentifierKind.Using;
|
|
3201
2597
|
break;
|