@typespec/compiler 0.41.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/LICENSE +21 -0
- package/README.md +9 -0
- package/cmd/tsp-server.js +3 -0
- package/cmd/tsp.js +3 -0
- package/dist/cmd/runner.d.ts +9 -0
- package/dist/cmd/runner.d.ts.map +1 -0
- package/dist/cmd/runner.js +62 -0
- package/dist/cmd/runner.js.map +1 -0
- package/dist/config/config-interpolation.d.ts +11 -0
- package/dist/config/config-interpolation.d.ts.map +1 -0
- package/dist/config/config-interpolation.js +109 -0
- package/dist/config/config-interpolation.js.map +1 -0
- package/dist/config/config-loader.d.ts +25 -0
- package/dist/config/config-loader.d.ts.map +1 -0
- package/dist/config/config-loader.js +182 -0
- package/dist/config/config-loader.js.map +1 -0
- package/dist/config/config-schema.d.ts +4 -0
- package/dist/config/config-schema.d.ts.map +1 -0
- package/dist/config/config-schema.js +84 -0
- package/dist/config/config-schema.js.map +1 -0
- package/dist/config/index.d.ts +3 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +3 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/types.d.ts +79 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/types.js +2 -0
- package/dist/config/types.js.map +1 -0
- package/dist/core/binder.d.ts +29 -0
- package/dist/core/binder.d.ts.map +1 -0
- package/dist/core/binder.js +455 -0
- package/dist/core/binder.js.map +1 -0
- package/dist/core/charcode.d.ts +130 -0
- package/dist/core/charcode.d.ts.map +1 -0
- package/dist/core/charcode.js +115 -0
- package/dist/core/charcode.js.map +1 -0
- package/dist/core/checker.d.ts +138 -0
- package/dist/core/checker.d.ts.map +1 -0
- package/dist/core/checker.js +4070 -0
- package/dist/core/checker.js.map +1 -0
- package/dist/core/cli/args.d.ts +18 -0
- package/dist/core/cli/args.d.ts.map +1 -0
- package/dist/core/cli/args.js +108 -0
- package/dist/core/cli/args.js.map +1 -0
- package/dist/core/cli/cli.d.ts +2 -0
- package/dist/core/cli/cli.d.ts.map +1 -0
- package/dist/core/cli/cli.js +477 -0
- package/dist/core/cli/cli.js.map +1 -0
- package/dist/core/cli/index.d.ts +2 -0
- package/dist/core/cli/index.d.ts.map +1 -0
- package/dist/core/cli/index.js +2 -0
- package/dist/core/cli/index.js.map +1 -0
- package/dist/core/decorator-utils.d.ts +108 -0
- package/dist/core/decorator-utils.d.ts.map +1 -0
- package/dist/core/decorator-utils.js +326 -0
- package/dist/core/decorator-utils.js.map +1 -0
- package/dist/core/diagnostics.d.ts +93 -0
- package/dist/core/diagnostics.d.ts.map +1 -0
- package/dist/core/diagnostics.js +315 -0
- package/dist/core/diagnostics.js.map +1 -0
- package/dist/core/emitter-utils.d.ts +14 -0
- package/dist/core/emitter-utils.d.ts.map +1 -0
- package/dist/core/emitter-utils.js +16 -0
- package/dist/core/emitter-utils.js.map +1 -0
- package/dist/core/formatter-fs.d.ts +21 -0
- package/dist/core/formatter-fs.d.ts.map +1 -0
- package/dist/core/formatter-fs.js +79 -0
- package/dist/core/formatter-fs.js.map +1 -0
- package/dist/core/formatter.d.ts +10 -0
- package/dist/core/formatter.d.ts.map +1 -0
- package/dist/core/formatter.js +24 -0
- package/dist/core/formatter.js.map +1 -0
- package/dist/core/helpers/discriminator-utils.d.ts +14 -0
- package/dist/core/helpers/discriminator-utils.d.ts.map +1 -0
- package/dist/core/helpers/discriminator-utils.js +169 -0
- package/dist/core/helpers/discriminator-utils.js.map +1 -0
- package/dist/core/helpers/index.d.ts +6 -0
- package/dist/core/helpers/index.d.ts.map +1 -0
- package/dist/core/helpers/index.js +6 -0
- package/dist/core/helpers/index.js.map +1 -0
- package/dist/core/helpers/operation-utils.d.ts +15 -0
- package/dist/core/helpers/operation-utils.d.ts.map +1 -0
- package/dist/core/helpers/operation-utils.js +35 -0
- package/dist/core/helpers/operation-utils.js.map +1 -0
- package/dist/core/helpers/projected-names-utils.d.ts +20 -0
- package/dist/core/helpers/projected-names-utils.d.ts.map +1 -0
- package/dist/core/helpers/projected-names-utils.js +40 -0
- package/dist/core/helpers/projected-names-utils.js.map +1 -0
- package/dist/core/helpers/type-name-utils.d.ts +14 -0
- package/dist/core/helpers/type-name-utils.d.ts.map +1 -0
- package/dist/core/helpers/type-name-utils.js +122 -0
- package/dist/core/helpers/type-name-utils.js.map +1 -0
- package/dist/core/helpers/usage-resolver.d.ts +20 -0
- package/dist/core/helpers/usage-resolver.d.ts.map +1 -0
- package/dist/core/helpers/usage-resolver.js +108 -0
- package/dist/core/helpers/usage-resolver.js.map +1 -0
- package/dist/core/index.d.ts +26 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +26 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/install.d.ts +2 -0
- package/dist/core/install.d.ts.map +1 -0
- package/dist/core/install.js +26 -0
- package/dist/core/install.js.map +1 -0
- package/dist/core/library.d.ts +34 -0
- package/dist/core/library.d.ts.map +1 -0
- package/dist/core/library.js +100 -0
- package/dist/core/library.js.map +1 -0
- package/dist/core/logger/console-sink.browser.d.ts +4 -0
- package/dist/core/logger/console-sink.browser.d.ts.map +1 -0
- package/dist/core/logger/console-sink.browser.js +14 -0
- package/dist/core/logger/console-sink.browser.js.map +1 -0
- package/dist/core/logger/console-sink.d.ts +9 -0
- package/dist/core/logger/console-sink.d.ts.map +1 -0
- package/dist/core/logger/console-sink.js +81 -0
- package/dist/core/logger/console-sink.js.map +1 -0
- package/dist/core/logger/index.d.ts +3 -0
- package/dist/core/logger/index.d.ts.map +1 -0
- package/dist/core/logger/index.js +3 -0
- package/dist/core/logger/index.js.map +1 -0
- package/dist/core/logger/logger.d.ts +7 -0
- package/dist/core/logger/logger.d.ts.map +1 -0
- package/dist/core/logger/logger.js +32 -0
- package/dist/core/logger/logger.js.map +1 -0
- package/dist/core/logger/tracer.d.ts +3 -0
- package/dist/core/logger/tracer.d.ts.map +1 -0
- package/dist/core/logger/tracer.js +91 -0
- package/dist/core/logger/tracer.js.map +1 -0
- package/dist/core/manifest.d.ts +21 -0
- package/dist/core/manifest.d.ts.map +1 -0
- package/dist/core/manifest.js +8 -0
- package/dist/core/manifest.js.map +1 -0
- package/dist/core/messages.d.ts +2253 -0
- package/dist/core/messages.d.ts.map +1 -0
- package/dist/core/messages.js +749 -0
- package/dist/core/messages.js.map +1 -0
- package/dist/core/module-resolver.d.ts +84 -0
- package/dist/core/module-resolver.d.ts.map +1 -0
- package/dist/core/module-resolver.js +170 -0
- package/dist/core/module-resolver.js.map +1 -0
- package/dist/core/node-host.browser.d.ts +2 -0
- package/dist/core/node-host.browser.d.ts.map +1 -0
- package/dist/core/node-host.browser.js +2 -0
- package/dist/core/node-host.browser.js.map +1 -0
- package/dist/core/node-host.d.ts +7 -0
- package/dist/core/node-host.d.ts.map +1 -0
- package/dist/core/node-host.js +43 -0
- package/dist/core/node-host.js.map +1 -0
- package/dist/core/nonascii.d.ts +2 -0
- package/dist/core/nonascii.d.ts.map +1 -0
- package/dist/core/nonascii.js +712 -0
- package/dist/core/nonascii.js.map +1 -0
- package/dist/core/options.d.ts +46 -0
- package/dist/core/options.d.ts.map +1 -0
- package/dist/core/options.js +2 -0
- package/dist/core/options.js.map +1 -0
- package/dist/core/parser.d.ts +17 -0
- package/dist/core/parser.d.ts.map +1 -0
- package/dist/core/parser.js +2561 -0
- package/dist/core/parser.js.map +1 -0
- package/dist/core/path-utils.d.ts +193 -0
- package/dist/core/path-utils.d.ts.map +1 -0
- package/dist/core/path-utils.js +427 -0
- package/dist/core/path-utils.js.map +1 -0
- package/dist/core/program.d.ts +104 -0
- package/dist/core/program.d.ts.map +1 -0
- package/dist/core/program.js +898 -0
- package/dist/core/program.js.map +1 -0
- package/dist/core/projection-members.d.ts +8 -0
- package/dist/core/projection-members.d.ts.map +1 -0
- package/dist/core/projection-members.js +387 -0
- package/dist/core/projection-members.js.map +1 -0
- package/dist/core/projector.d.ts +26 -0
- package/dist/core/projector.d.ts.map +1 -0
- package/dist/core/projector.js +523 -0
- package/dist/core/projector.js.map +1 -0
- package/dist/core/scanner.d.ts +125 -0
- package/dist/core/scanner.d.ts.map +1 -0
- package/dist/core/scanner.js +1012 -0
- package/dist/core/scanner.js.map +1 -0
- package/dist/core/schema-validator.d.ts +6 -0
- package/dist/core/schema-validator.d.ts.map +1 -0
- package/dist/core/schema-validator.js +38 -0
- package/dist/core/schema-validator.js.map +1 -0
- package/dist/core/semantic-walker.d.ts +53 -0
- package/dist/core/semantic-walker.d.ts.map +1 -0
- package/dist/core/semantic-walker.js +355 -0
- package/dist/core/semantic-walker.js.map +1 -0
- package/dist/core/type-utils.d.ts +49 -0
- package/dist/core/type-utils.d.ts.map +1 -0
- package/dist/core/type-utils.js +95 -0
- package/dist/core/type-utils.js.map +1 -0
- package/dist/core/types.d.ts +1345 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +105 -0
- package/dist/core/types.js.map +1 -0
- package/dist/core/util.d.ts +150 -0
- package/dist/core/util.d.ts.map +1 -0
- package/dist/core/util.js +417 -0
- package/dist/core/util.js.map +1 -0
- package/dist/emitter-framework/asset-emitter.d.ts +5 -0
- package/dist/emitter-framework/asset-emitter.d.ts.map +1 -0
- package/dist/emitter-framework/asset-emitter.js +610 -0
- package/dist/emitter-framework/asset-emitter.js.map +1 -0
- package/dist/emitter-framework/builders/array-builder.d.ts +7 -0
- package/dist/emitter-framework/builders/array-builder.d.ts.map +1 -0
- package/dist/emitter-framework/builders/array-builder.js +45 -0
- package/dist/emitter-framework/builders/array-builder.js.map +1 -0
- package/dist/emitter-framework/builders/object-builder.d.ts +9 -0
- package/dist/emitter-framework/builders/object-builder.d.ts.map +1 -0
- package/dist/emitter-framework/builders/object-builder.js +30 -0
- package/dist/emitter-framework/builders/object-builder.js.map +1 -0
- package/dist/emitter-framework/builders/string-builder.d.ts +13 -0
- package/dist/emitter-framework/builders/string-builder.d.ts.map +1 -0
- package/dist/emitter-framework/builders/string-builder.js +98 -0
- package/dist/emitter-framework/builders/string-builder.js.map +1 -0
- package/dist/emitter-framework/custom-key-map.d.ts +29 -0
- package/dist/emitter-framework/custom-key-map.d.ts.map +1 -0
- package/dist/emitter-framework/custom-key-map.js +62 -0
- package/dist/emitter-framework/custom-key-map.js.map +1 -0
- package/dist/emitter-framework/index.d.ts +8 -0
- package/dist/emitter-framework/index.d.ts.map +1 -0
- package/dist/emitter-framework/index.js +8 -0
- package/dist/emitter-framework/index.js.map +1 -0
- package/dist/emitter-framework/placeholder.d.ts +12 -0
- package/dist/emitter-framework/placeholder.d.ts.map +1 -0
- package/dist/emitter-framework/placeholder.js +27 -0
- package/dist/emitter-framework/placeholder.js.map +1 -0
- package/dist/emitter-framework/type-emitter.d.ts +314 -0
- package/dist/emitter-framework/type-emitter.d.ts.map +1 -0
- package/dist/emitter-framework/type-emitter.js +612 -0
- package/dist/emitter-framework/type-emitter.js.map +1 -0
- package/dist/emitter-framework/types.d.ts +124 -0
- package/dist/emitter-framework/types.d.ts.map +1 -0
- package/dist/emitter-framework/types.js +39 -0
- package/dist/emitter-framework/types.js.map +1 -0
- package/dist/formatter/index.d.ts +11 -0
- package/dist/formatter/index.d.ts.map +1 -0
- package/dist/formatter/index.js +28 -0
- package/dist/formatter/index.js.map +1 -0
- package/dist/formatter/parser.d.ts +16 -0
- package/dist/formatter/parser.d.ts.map +1 -0
- package/dist/formatter/parser.js +23 -0
- package/dist/formatter/parser.js.map +1 -0
- package/dist/formatter/print/comment-handler.d.ts +7 -0
- package/dist/formatter/print/comment-handler.d.ts.map +1 -0
- package/dist/formatter/print/comment-handler.js +81 -0
- package/dist/formatter/print/comment-handler.js.map +1 -0
- package/dist/formatter/print/index.d.ts +3 -0
- package/dist/formatter/print/index.d.ts.map +1 -0
- package/dist/formatter/print/index.js +3 -0
- package/dist/formatter/print/index.js.map +1 -0
- package/dist/formatter/print/needs-parens.d.ts +10 -0
- package/dist/formatter/print/needs-parens.d.ts.map +1 -0
- package/dist/formatter/print/needs-parens.js +27 -0
- package/dist/formatter/print/needs-parens.js.map +1 -0
- package/dist/formatter/print/printer.d.ts +62 -0
- package/dist/formatter/print/printer.d.ts.map +1 -0
- package/dist/formatter/print/printer.js +1025 -0
- package/dist/formatter/print/printer.js.map +1 -0
- package/dist/formatter/print/types.d.ts +9 -0
- package/dist/formatter/print/types.d.ts.map +1 -0
- package/dist/formatter/print/types.js +2 -0
- package/dist/formatter/print/types.js.map +1 -0
- package/dist/init/index.d.ts +2 -0
- package/dist/init/index.d.ts.map +1 -0
- package/dist/init/index.js +2 -0
- package/dist/init/index.js.map +1 -0
- package/dist/init/init-template.d.ts +45 -0
- package/dist/init/init-template.d.ts.map +1 -0
- package/dist/init/init-template.js +45 -0
- package/dist/init/init-template.js.map +1 -0
- package/dist/init/init.d.ts +49 -0
- package/dist/init/init.d.ts.map +1 -0
- package/dist/init/init.js +224 -0
- package/dist/init/init.js.map +1 -0
- package/dist/lib/decorators.d.ts +222 -0
- package/dist/lib/decorators.d.ts.map +1 -0
- package/dist/lib/decorators.js +745 -0
- package/dist/lib/decorators.js.map +1 -0
- package/dist/lib/service.d.ts +38 -0
- package/dist/lib/service.d.ts.map +1 -0
- package/dist/lib/service.js +78 -0
- package/dist/lib/service.js.map +1 -0
- package/dist/manifest.js +4 -0
- package/dist/server/completion.d.ts +10 -0
- package/dist/server/completion.d.ts.map +1 -0
- package/dist/server/completion.js +207 -0
- package/dist/server/completion.js.map +1 -0
- package/dist/server/index.d.ts +3 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +3 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/language-config.d.ts +195 -0
- package/dist/server/language-config.d.ts.map +1 -0
- package/dist/server/language-config.js +102 -0
- package/dist/server/language-config.js.map +1 -0
- package/dist/server/server.d.ts +2 -0
- package/dist/server/server.d.ts.map +1 -0
- package/dist/server/server.js +131 -0
- package/dist/server/server.js.map +1 -0
- package/dist/server/serverlib.d.ts +72 -0
- package/dist/server/serverlib.d.ts.map +1 -0
- package/dist/server/serverlib.js +1034 -0
- package/dist/server/serverlib.js.map +1 -0
- package/dist/server/symbol-structure.d.ts +4 -0
- package/dist/server/symbol-structure.d.ts.map +1 -0
- package/dist/server/symbol-structure.js +121 -0
- package/dist/server/symbol-structure.js.map +1 -0
- package/dist/server/tmlanguage.d.ts +3 -0
- package/dist/server/tmlanguage.d.ts.map +1 -0
- package/dist/server/tmlanguage.js +713 -0
- package/dist/server/tmlanguage.js.map +1 -0
- package/dist/server/type-details.d.ts +11 -0
- package/dist/server/type-details.d.ts.map +1 -0
- package/dist/server/type-details.js +72 -0
- package/dist/server/type-details.js.map +1 -0
- package/dist/server/type-signature.d.ts +2 -0
- package/dist/server/type-signature.d.ts.map +1 -0
- package/dist/server/type-signature.js +108 -0
- package/dist/server/type-signature.js.map +1 -0
- package/dist/testing/expect.d.ts +49 -0
- package/dist/testing/expect.d.ts.map +1 -0
- package/dist/testing/expect.js +83 -0
- package/dist/testing/expect.js.map +1 -0
- package/dist/testing/index.d.ts +6 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +6 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/test-host.d.ts +14 -0
- package/dist/testing/test-host.d.ts.map +1 -0
- package/dist/testing/test-host.js +271 -0
- package/dist/testing/test-host.js.map +1 -0
- package/dist/testing/test-server-host.d.ts +39 -0
- package/dist/testing/test-server-host.d.ts.map +1 -0
- package/dist/testing/test-server-host.js +112 -0
- package/dist/testing/test-server-host.js.map +1 -0
- package/dist/testing/test-utils.d.ts +22 -0
- package/dist/testing/test-utils.d.ts.map +1 -0
- package/dist/testing/test-utils.js +60 -0
- package/dist/testing/test-utils.js.map +1 -0
- package/dist/testing/types.d.ts +69 -0
- package/dist/testing/types.d.ts.map +1 -0
- package/dist/testing/types.js +7 -0
- package/dist/testing/types.js.map +1 -0
- package/dist/typespec.tmLanguage +1760 -0
- package/lib/decorators.tsp +420 -0
- package/lib/lib.tsp +158 -0
- package/lib/main.tsp +4 -0
- package/lib/projected-names.tsp +94 -0
- package/lib/reflection.tsp +10 -0
- package/package.json +119 -0
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import { formatLog } from "./logger/index.js";
|
|
2
|
+
import { reportDiagnostic } from "./messages.js";
|
|
3
|
+
import { NoTarget, SyntaxKind, } from "./types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Create a new diagnostics creator.
|
|
6
|
+
* @param diagnostics Map of the potential diagnostics.
|
|
7
|
+
* @param libraryName Optional name of the library if in the scope of a library.
|
|
8
|
+
* @returns @see DiagnosticCreator
|
|
9
|
+
*/
|
|
10
|
+
export function createDiagnosticCreator(diagnostics, libraryName) {
|
|
11
|
+
const errorMessage = libraryName
|
|
12
|
+
? `It must match one of the code defined in the library '${libraryName}'`
|
|
13
|
+
: "It must match one of the code defined in the compiler.";
|
|
14
|
+
function createDiagnostic(diagnostic) {
|
|
15
|
+
var _a;
|
|
16
|
+
const diagnosticDef = diagnostics[diagnostic.code];
|
|
17
|
+
if (!diagnosticDef) {
|
|
18
|
+
const codeStr = Object.keys(diagnostics)
|
|
19
|
+
.map((x) => ` - ${x}`)
|
|
20
|
+
.join("\n");
|
|
21
|
+
const code = String(diagnostic.code);
|
|
22
|
+
throw new Error(`Unexpected diagnostic code '${code}'. ${errorMessage}. Defined codes:\n${codeStr}`);
|
|
23
|
+
}
|
|
24
|
+
const message = diagnosticDef.messages[(_a = diagnostic.messageId) !== null && _a !== void 0 ? _a : "default"];
|
|
25
|
+
if (!message) {
|
|
26
|
+
const codeStr = Object.keys(diagnosticDef.messages)
|
|
27
|
+
.map((x) => ` - ${x}`)
|
|
28
|
+
.join("\n");
|
|
29
|
+
const messageId = String(diagnostic.messageId);
|
|
30
|
+
const code = String(diagnostic.code);
|
|
31
|
+
throw new Error(`Unexpected message id '${messageId}'. ${errorMessage} for code '${code}'. Defined codes:\n${codeStr}`);
|
|
32
|
+
}
|
|
33
|
+
const messageStr = typeof message === "string" ? message : message(diagnostic.format);
|
|
34
|
+
return {
|
|
35
|
+
code: libraryName ? `${libraryName}/${String(diagnostic.code)}` : diagnostic.code.toString(),
|
|
36
|
+
severity: diagnosticDef.severity,
|
|
37
|
+
message: messageStr,
|
|
38
|
+
target: diagnostic.target,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function reportDiagnostic(program, diagnostic) {
|
|
42
|
+
const diag = createDiagnostic(diagnostic);
|
|
43
|
+
program.reportDiagnostic(diag);
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
diagnostics,
|
|
47
|
+
createDiagnostic,
|
|
48
|
+
reportDiagnostic,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Represents a failure while interpreting a projection.
|
|
53
|
+
*/
|
|
54
|
+
export class ProjectionError extends Error {
|
|
55
|
+
constructor(message) {
|
|
56
|
+
super(message);
|
|
57
|
+
this.name = "ProjectionError";
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
export function logDiagnostics(diagnostics, logger) {
|
|
61
|
+
for (const diagnostic of diagnostics) {
|
|
62
|
+
logger.log({
|
|
63
|
+
level: diagnostic.severity,
|
|
64
|
+
message: diagnostic.message,
|
|
65
|
+
code: diagnostic.code,
|
|
66
|
+
sourceLocation: getSourceLocation(diagnostic.target),
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
export function formatDiagnostic(diagnostic) {
|
|
71
|
+
return formatLog({
|
|
72
|
+
code: diagnostic.code,
|
|
73
|
+
level: diagnostic.severity,
|
|
74
|
+
message: diagnostic.message,
|
|
75
|
+
sourceLocation: getSourceLocation(diagnostic.target),
|
|
76
|
+
}, { pretty: false });
|
|
77
|
+
}
|
|
78
|
+
export function createSourceFile(text, path) {
|
|
79
|
+
let lineStarts = undefined;
|
|
80
|
+
return {
|
|
81
|
+
text,
|
|
82
|
+
path,
|
|
83
|
+
getLineStarts,
|
|
84
|
+
getLineAndCharacterOfPosition,
|
|
85
|
+
};
|
|
86
|
+
function getLineStarts() {
|
|
87
|
+
return (lineStarts = lineStarts !== null && lineStarts !== void 0 ? lineStarts : scanLineStarts(text));
|
|
88
|
+
}
|
|
89
|
+
function getLineAndCharacterOfPosition(position) {
|
|
90
|
+
const starts = getLineStarts();
|
|
91
|
+
let line = binarySearch(starts, position);
|
|
92
|
+
// When binarySearch returns < 0 indicating that the value was not found, it
|
|
93
|
+
// returns the bitwise complement of the index where the value would need to
|
|
94
|
+
// be inserted to keep the array sorted. So flipping the bits back to this
|
|
95
|
+
// positive index tells us what the line number would be if we were to
|
|
96
|
+
// create a new line starting at the given position, and subtracting 1 from
|
|
97
|
+
// that therefore gives us the line number we're after.
|
|
98
|
+
if (line < 0) {
|
|
99
|
+
line = ~line - 1;
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
line,
|
|
103
|
+
character: position - starts[line],
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
export function getSourceLocation(target) {
|
|
108
|
+
if (target === NoTarget || target === undefined) {
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
if ("file" in target) {
|
|
112
|
+
return target;
|
|
113
|
+
}
|
|
114
|
+
if (!("kind" in target)) {
|
|
115
|
+
// symbol
|
|
116
|
+
if (target.flags & 524288 /* SymbolFlags.Using */) {
|
|
117
|
+
target = target.symbolSource;
|
|
118
|
+
}
|
|
119
|
+
if (!target.declarations[0]) {
|
|
120
|
+
return createSyntheticSourceLocation();
|
|
121
|
+
}
|
|
122
|
+
return getSourceLocationOfNode(target.declarations[0]);
|
|
123
|
+
}
|
|
124
|
+
else if (typeof target.kind === "number") {
|
|
125
|
+
// node
|
|
126
|
+
return getSourceLocationOfNode(target);
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
// type
|
|
130
|
+
const targetNode = target.node;
|
|
131
|
+
if (targetNode) {
|
|
132
|
+
return getSourceLocationOfNode(targetNode);
|
|
133
|
+
}
|
|
134
|
+
return createSyntheticSourceLocation();
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
function createSyntheticSourceLocation(loc = "<unknown location>") {
|
|
138
|
+
return {
|
|
139
|
+
file: createSourceFile("", loc),
|
|
140
|
+
pos: 0,
|
|
141
|
+
end: 0,
|
|
142
|
+
isSynthetic: true,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
function getSourceLocationOfNode(node) {
|
|
146
|
+
let root = node;
|
|
147
|
+
while (root.parent !== undefined) {
|
|
148
|
+
root = root.parent;
|
|
149
|
+
}
|
|
150
|
+
if (root.kind !== SyntaxKind.TypeSpecScript && root.kind !== SyntaxKind.JsSourceFile) {
|
|
151
|
+
return createSyntheticSourceLocation(node.flags & 8 /* NodeFlags.Synthetic */
|
|
152
|
+
? undefined
|
|
153
|
+
: "<unknown location - cannot obtain source location of unbound node - file bug at https://github.com/microsoft/typespec>");
|
|
154
|
+
}
|
|
155
|
+
return {
|
|
156
|
+
file: root.file,
|
|
157
|
+
pos: node.pos,
|
|
158
|
+
end: node.end,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Verbose output is enabled by default for runs in mocha explorer in VS Code,
|
|
163
|
+
* where the output is nicely associated with the individual test, and disabled
|
|
164
|
+
* by default for command line runs where we don't want to spam the console.
|
|
165
|
+
*
|
|
166
|
+
* If the steps taken to produce the message are expensive, pass a callback
|
|
167
|
+
* instead of producing the message then passing it here only to be dropped
|
|
168
|
+
* when verbose output is disabled.
|
|
169
|
+
*/
|
|
170
|
+
export function logVerboseTestOutput(messageOrCallback) {
|
|
171
|
+
if (process.env.TYPESPEC_VERBOSE_TEST_OUTPUT) {
|
|
172
|
+
if (typeof messageOrCallback === "string") {
|
|
173
|
+
// eslint-disable-next-line no-console
|
|
174
|
+
console.log(messageOrCallback);
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
// eslint-disable-next-line no-console
|
|
178
|
+
messageOrCallback(console.log);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Use this to report bugs in the compiler, and not errors in the source code
|
|
184
|
+
* being compiled.
|
|
185
|
+
*
|
|
186
|
+
* @param condition Throw if this is not true.
|
|
187
|
+
*
|
|
188
|
+
* @param message Error message.
|
|
189
|
+
*
|
|
190
|
+
* @param target Optional location in source code that might give a clue about
|
|
191
|
+
* what got the compiler off track.
|
|
192
|
+
*/
|
|
193
|
+
export function compilerAssert(condition, message, target) {
|
|
194
|
+
if (condition) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
if (target) {
|
|
198
|
+
let location;
|
|
199
|
+
try {
|
|
200
|
+
location = getSourceLocation(target);
|
|
201
|
+
}
|
|
202
|
+
catch (err) { }
|
|
203
|
+
if (location) {
|
|
204
|
+
const pos = location.file.getLineAndCharacterOfPosition(location.pos);
|
|
205
|
+
const file = location.file.path;
|
|
206
|
+
const line = pos.line + 1;
|
|
207
|
+
const col = pos.character + 1;
|
|
208
|
+
message += `\nOccurred while compiling code in ${file} near line ${line}, column ${col}`;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
throw new Error(message);
|
|
212
|
+
}
|
|
213
|
+
function scanLineStarts(text) {
|
|
214
|
+
const starts = [];
|
|
215
|
+
let start = 0;
|
|
216
|
+
let pos = 0;
|
|
217
|
+
while (pos < text.length) {
|
|
218
|
+
const ch = text.charCodeAt(pos);
|
|
219
|
+
pos++;
|
|
220
|
+
switch (ch) {
|
|
221
|
+
case 13 /* CharCode.CarriageReturn */:
|
|
222
|
+
if (text.charCodeAt(pos) === 10 /* CharCode.LineFeed */) {
|
|
223
|
+
pos++;
|
|
224
|
+
}
|
|
225
|
+
// fallthrough
|
|
226
|
+
case 10 /* CharCode.LineFeed */:
|
|
227
|
+
starts.push(start);
|
|
228
|
+
start = pos;
|
|
229
|
+
break;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
starts.push(start);
|
|
233
|
+
return starts;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Search sorted array of numbers for the given value. If found, return index
|
|
237
|
+
* in array where value was found. If not found, return a negative number that
|
|
238
|
+
* is the bitwise complement of the index where value would need to be inserted
|
|
239
|
+
* to keep the array sorted.
|
|
240
|
+
*/
|
|
241
|
+
function binarySearch(array, value) {
|
|
242
|
+
let low = 0;
|
|
243
|
+
let high = array.length - 1;
|
|
244
|
+
while (low <= high) {
|
|
245
|
+
const middle = low + ((high - low) >> 1);
|
|
246
|
+
const v = array[middle];
|
|
247
|
+
if (v < value) {
|
|
248
|
+
low = middle + 1;
|
|
249
|
+
}
|
|
250
|
+
else if (v > value) {
|
|
251
|
+
high = middle - 1;
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
return middle;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return ~low;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Assert that the input type has one of the kinds provided
|
|
261
|
+
*/
|
|
262
|
+
export function assertType(typeDescription, t, ...kinds) {
|
|
263
|
+
if (kinds.indexOf(t.kind) === -1) {
|
|
264
|
+
throw new ProjectionError(`Expected ${typeDescription} to be type ${kinds.join(", ")}`);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Report a deprecated diagnostic.
|
|
269
|
+
* @param program TypeSpec Program.
|
|
270
|
+
* @param message Message describing the deprecation.
|
|
271
|
+
* @param target Target of the deprecation.
|
|
272
|
+
*/
|
|
273
|
+
export function reportDeprecated(program, message, target) {
|
|
274
|
+
reportDiagnostic(program, {
|
|
275
|
+
code: "deprecated",
|
|
276
|
+
format: {
|
|
277
|
+
message,
|
|
278
|
+
},
|
|
279
|
+
target,
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Create a new instance of the @see DiagnosticCollector.
|
|
284
|
+
*/
|
|
285
|
+
export function createDiagnosticCollector() {
|
|
286
|
+
const diagnostics = [];
|
|
287
|
+
return {
|
|
288
|
+
diagnostics,
|
|
289
|
+
add,
|
|
290
|
+
pipe,
|
|
291
|
+
wrap,
|
|
292
|
+
};
|
|
293
|
+
function add(diagnostic) {
|
|
294
|
+
diagnostics.push(diagnostic);
|
|
295
|
+
}
|
|
296
|
+
function pipe(result) {
|
|
297
|
+
const [value, diags] = result;
|
|
298
|
+
for (const diag of diags) {
|
|
299
|
+
diagnostics.push(diag);
|
|
300
|
+
}
|
|
301
|
+
return value;
|
|
302
|
+
}
|
|
303
|
+
function wrap(value) {
|
|
304
|
+
return [value, diagnostics];
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Ignore the diagnostics emitted by the diagnostic accessor pattern and just return the actual result.
|
|
309
|
+
* @param result: Accessor pattern tuple result including the actual result and the list of diagnostics.
|
|
310
|
+
* @returns Actual result.
|
|
311
|
+
*/
|
|
312
|
+
export function ignoreDiagnostics(result) {
|
|
313
|
+
return result[0];
|
|
314
|
+
}
|
|
315
|
+
//# sourceMappingURL=diagnostics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnostics.js","sourceRoot":"","sources":["../../core/diagnostics.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEjD,OAAO,EAWL,QAAQ,EAIR,UAAU,GAEX,MAAM,YAAY,CAAC;AAEpB;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CACrC,WAA6B,EAC7B,WAAoB;IAEpB,MAAM,YAAY,GAAG,WAAW;QAC9B,CAAC,CAAC,yDAAyD,WAAW,GAAG;QACzE,CAAC,CAAC,wDAAwD,CAAC;IAE7D,SAAS,gBAAgB,CACvB,UAAqC;;QAErC,MAAM,aAAa,GAAG,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QAEnD,IAAI,CAAC,aAAa,EAAE;YAClB,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,C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AO;QACL,WAAW;QACX,GAAG;QACH,IAAI;QACJ,IAAI;KACL,CAAC;IAEF,SAAS,GAAG,CAAC,UAAsB;QACjC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAC/B,CAAC;IAED,SAAS,IAAI,CAAI,MAA2B;QAC1C,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,MAAM,CAAC;QAC9B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;YACxB,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SACxB;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,SAAS,IAAI,CAAI,KAAQ;QACvB,OAAO,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;IAC9B,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAI,MAA2B;IAC9D,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Program } from "./program.js";
|
|
2
|
+
export type NewLine = "lf" | "crlf";
|
|
3
|
+
export interface EmitFileOptions {
|
|
4
|
+
path: string;
|
|
5
|
+
content: string;
|
|
6
|
+
newLine?: NewLine;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Helper to emit a file.
|
|
10
|
+
* @param program TypeSpec Program
|
|
11
|
+
* @param options File Emitter options
|
|
12
|
+
*/
|
|
13
|
+
export declare function emitFile(program: Program, options: EmitFileOptions): Promise<void>;
|
|
14
|
+
//# sourceMappingURL=emitter-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emitter-utils.d.ts","sourceRoot":"","sources":["../../core/emitter-utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,MAAM,MAAM,OAAO,GAAG,IAAI,GAAG,MAAM,CAAC;AACpC,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;GAIG;AACH,wBAAsB,QAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CASxF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { getDirectoryPath } from "./path-utils.js";
|
|
2
|
+
/**
|
|
3
|
+
* Helper to emit a file.
|
|
4
|
+
* @param program TypeSpec Program
|
|
5
|
+
* @param options File Emitter options
|
|
6
|
+
*/
|
|
7
|
+
export async function emitFile(program, options) {
|
|
8
|
+
// ensure path exists
|
|
9
|
+
const outputFolder = getDirectoryPath(options.path);
|
|
10
|
+
await program.host.mkdirp(outputFolder);
|
|
11
|
+
const content = options.newLine && options.newLine === "crlf"
|
|
12
|
+
? options.content.replace(/(\r\n|\n|\r)/gm, "\r\n")
|
|
13
|
+
: options.content;
|
|
14
|
+
return await program.host.writeFile(options.path, content);
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=emitter-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emitter-utils.js","sourceRoot":"","sources":["../../core/emitter-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAUnD;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,OAAgB,EAAE,OAAwB;IACvE,qBAAqB;IACrB,MAAM,YAAY,GAAG,gBAAgB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACpD,MAAM,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;IACxC,MAAM,OAAO,GACX,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,KAAK,MAAM;QAC3C,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,gBAAgB,EAAE,MAAM,CAAC;QACnD,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC;IACtB,OAAO,MAAM,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAC7D,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface TypeSpecFormatOptions {
|
|
2
|
+
exclude?: string[];
|
|
3
|
+
debug?: boolean;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Format all the TypeSpec files.
|
|
7
|
+
* @param patterns List of wildcard pattern searching for TypeSpec files.
|
|
8
|
+
*/
|
|
9
|
+
export declare function formatTypeSpecFiles(patterns: string[], { exclude, debug }: TypeSpecFormatOptions): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Find all the unformatted files.
|
|
12
|
+
* @returns list of files not formatted.
|
|
13
|
+
*/
|
|
14
|
+
export declare function findUnformattedTypeSpecFiles(patterns: string[], { exclude, debug }: TypeSpecFormatOptions): Promise<string[]>;
|
|
15
|
+
export declare function formatTypeSpecFile(filename: string): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Check the given typespec file is correctly formatted.
|
|
18
|
+
* @returns true if code is formatted correctly.
|
|
19
|
+
*/
|
|
20
|
+
export declare function checkFormatTypeSpecFile(filename: string): Promise<boolean>;
|
|
21
|
+
//# sourceMappingURL=formatter-fs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatter-fs.d.ts","sourceRoot":"","sources":["../../core/formatter-fs.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,qBAAqB;IACpC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;;GAGG;AACH,wBAAsB,mBAAmB,CACvC,QAAQ,EAAE,MAAM,EAAE,EAClB,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,qBAAqB,iBAgB1C;AAED;;;GAGG;AACH,wBAAsB,4BAA4B,CAChD,QAAQ,EAAE,MAAM,EAAE,EAClB,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,qBAAqB,GACxC,OAAO,CAAC,MAAM,EAAE,CAAC,CAoBnB;AAED,wBAAsB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,iBAKxD;AAED;;;GAGG;AACH,wBAAsB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAIhF"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { readFile, writeFile } from "fs/promises";
|
|
2
|
+
import { globby } from "globby";
|
|
3
|
+
import prettier from "prettier";
|
|
4
|
+
import { PrettierParserError } from "../formatter/parser.js";
|
|
5
|
+
import { checkFormatTypeSpec, formatTypeSpec } from "./formatter.js";
|
|
6
|
+
import { normalizePath } from "./path-utils.js";
|
|
7
|
+
/**
|
|
8
|
+
* Format all the TypeSpec files.
|
|
9
|
+
* @param patterns List of wildcard pattern searching for TypeSpec files.
|
|
10
|
+
*/
|
|
11
|
+
export async function formatTypeSpecFiles(patterns, { exclude, debug }) {
|
|
12
|
+
const files = await findFiles(patterns, exclude);
|
|
13
|
+
for (const file of files) {
|
|
14
|
+
try {
|
|
15
|
+
await formatTypeSpecFile(file);
|
|
16
|
+
}
|
|
17
|
+
catch (e) {
|
|
18
|
+
if (e instanceof PrettierParserError) {
|
|
19
|
+
const details = debug ? e.message : "";
|
|
20
|
+
// eslint-disable-next-line no-console
|
|
21
|
+
console.error(`File '${file}' failed to fromat. ${details}`);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
throw e;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Find all the unformatted files.
|
|
31
|
+
* @returns list of files not formatted.
|
|
32
|
+
*/
|
|
33
|
+
export async function findUnformattedTypeSpecFiles(patterns, { exclude, debug }) {
|
|
34
|
+
const files = await findFiles(patterns, exclude);
|
|
35
|
+
const unformatted = [];
|
|
36
|
+
for (const file of files) {
|
|
37
|
+
try {
|
|
38
|
+
if (!(await checkFormatTypeSpecFile(file))) {
|
|
39
|
+
unformatted.push(file);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
if (e instanceof PrettierParserError) {
|
|
44
|
+
const details = debug ? e.message : "";
|
|
45
|
+
// eslint-disable-next-line no-console
|
|
46
|
+
console.error(`File '${file}' failed to fromat. ${details}`);
|
|
47
|
+
unformatted.push(file);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
throw e;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return unformatted;
|
|
55
|
+
}
|
|
56
|
+
export async function formatTypeSpecFile(filename) {
|
|
57
|
+
const content = await readFile(filename, "utf-8");
|
|
58
|
+
const prettierConfig = await prettier.resolveConfig(filename);
|
|
59
|
+
const formattedContent = formatTypeSpec(content, prettierConfig !== null && prettierConfig !== void 0 ? prettierConfig : {});
|
|
60
|
+
await writeFile(filename, formattedContent);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Check the given typespec file is correctly formatted.
|
|
64
|
+
* @returns true if code is formatted correctly.
|
|
65
|
+
*/
|
|
66
|
+
export async function checkFormatTypeSpecFile(filename) {
|
|
67
|
+
const content = await readFile(filename, "utf-8");
|
|
68
|
+
const prettierConfig = await prettier.resolveConfig(filename);
|
|
69
|
+
return await checkFormatTypeSpec(content, prettierConfig !== null && prettierConfig !== void 0 ? prettierConfig : {});
|
|
70
|
+
}
|
|
71
|
+
async function findFiles(include, ignore = []) {
|
|
72
|
+
const patterns = [
|
|
73
|
+
...include.map(normalizePath),
|
|
74
|
+
"!**/node_modules",
|
|
75
|
+
...ignore.map((x) => `!${normalizePath(x)}`),
|
|
76
|
+
];
|
|
77
|
+
return globby(patterns);
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=formatter-fs.js.map
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Ac,GAAI,EAAE,CAAC,CAAC;AAClE,CAAC;AAED,KAAK,UAAU,SAAS,CAAC,OAAiB,EAAE,SAAmB,EAAE;IAC/D,MAAM,QAAQ,GAAG;QACf,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC;QAC7B,kBAAkB;QAClB,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC;KAC7C,CAAC;IACF,OAAO,MAAM,CAAC,QAAQ,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import prettier from "prettier";
|
|
2
|
+
export declare function formatTypeSpec(code: string, prettierConfig?: prettier.Options): string;
|
|
3
|
+
/** @deprecated use checkFormatTypeSpec */
|
|
4
|
+
export declare const checkFormatCadl: typeof checkFormatTypeSpec;
|
|
5
|
+
/**
|
|
6
|
+
* Check the given is correctly formatted.
|
|
7
|
+
* @returns true if code is formatted correctly.
|
|
8
|
+
*/
|
|
9
|
+
export declare function checkFormatTypeSpec(code: string, prettierConfig?: prettier.Options): Promise<boolean>;
|
|
10
|
+
//# sourceMappingURL=formatter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../../core/formatter.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAGhC,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,QAAQ,CAAC,OAAO,GAAG,MAAM,CAQtF;AAED,0CAA0C;AAC1C,eAAO,MAAM,eAAe,4BAAsB,CAAC;AAEnD;;;GAGG;AACH,wBAAsB,mBAAmB,CACvC,IAAI,EAAE,MAAM,EACZ,cAAc,CAAC,EAAE,QAAQ,CAAC,OAAO,GAChC,OAAO,CAAC,OAAO,CAAC,CAMlB"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import prettier from "prettier";
|
|
2
|
+
import * as typespecPrettierPlugin from "../formatter/index.js";
|
|
3
|
+
export function formatTypeSpec(code, prettierConfig) {
|
|
4
|
+
const output = prettier.format(code, {
|
|
5
|
+
...prettierConfig,
|
|
6
|
+
parser: "typespec",
|
|
7
|
+
plugins: [typespecPrettierPlugin],
|
|
8
|
+
});
|
|
9
|
+
return output;
|
|
10
|
+
}
|
|
11
|
+
/** @deprecated use checkFormatTypeSpec */
|
|
12
|
+
export const checkFormatCadl = checkFormatTypeSpec;
|
|
13
|
+
/**
|
|
14
|
+
* Check the given is correctly formatted.
|
|
15
|
+
* @returns true if code is formatted correctly.
|
|
16
|
+
*/
|
|
17
|
+
export async function checkFormatTypeSpec(code, prettierConfig) {
|
|
18
|
+
return prettier.check(code, {
|
|
19
|
+
...prettierConfig,
|
|
20
|
+
parser: "typespec",
|
|
21
|
+
plugins: [typespecPrettierPlugin],
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=formatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatter.js","sourceRoot":"","sources":["../../core/formatter.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,KAAK,sBAAsB,MAAM,uBAAuB,CAAC;AAEhE,MAAM,UAAU,cAAc,CAAC,IAAY,EAAE,cAAiC;IAC5E,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE;QACnC,GAAG,cAAc;QACjB,MAAM,EAAE,UAAU;QAClB,OAAO,EAAE,CAAC,sBAAsB,CAAC;KAClC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,0CAA0C;AAC1C,MAAM,CAAC,MAAM,eAAe,GAAG,mBAAmB,CAAC;AAEnD;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,IAAY,EACZ,cAAiC;IAEjC,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE;QAC1B,GAAG,cAAc;QACjB,MAAM,EAAE,UAAU;QAClB,OAAO,EAAE,CAAC,sBAAsB,CAAC;KAClC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Discriminator } from "../../lib/decorators.js";
|
|
2
|
+
import { Program } from "../program.js";
|
|
3
|
+
import { Diagnostic, Model, Union } from "../types.js";
|
|
4
|
+
export interface DiscriminatedUnion {
|
|
5
|
+
propertyName: string;
|
|
6
|
+
variants: Map<string, Model>;
|
|
7
|
+
}
|
|
8
|
+
export declare function getDiscriminatedUnion(type: Model | Union, discriminator: Discriminator): [DiscriminatedUnion, readonly Diagnostic[]];
|
|
9
|
+
/**
|
|
10
|
+
* Run the validation on all discriminated models to make sure the discriminator are valid.
|
|
11
|
+
* This has to be done after the checker so we can have the full picture of all the dervied models.
|
|
12
|
+
*/
|
|
13
|
+
export declare function validateInheritanceDiscriminatedUnions(program: Program): void;
|
|
14
|
+
//# sourceMappingURL=discriminator-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discriminator-utils.d.ts","sourceRoot":"","sources":["../../../core/helpers/discriminator-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAyB,MAAM,yBAAyB,CAAC;AAE/E,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,UAAU,EAAE,KAAK,EAAQ,KAAK,EAAE,MAAM,aAAa,CAAC;AAG7D,MAAM,WAAW,kBAAkB;IACjC,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;CAC9B;AAED,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,KAAK,GAAG,KAAK,EACnB,aAAa,EAAE,aAAa,GAC3B,CAAC,kBAAkB,EAAE,SAAS,UAAU,EAAE,CAAC,CAO7C;AAED;;;GAGG;AACH,wBAAgB,sCAAsC,CAAC,OAAO,EAAE,OAAO,QAQtE"}
|