mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Add transpileDeclaration API method (#58261)
This commit is contained in:
@@ -533,7 +533,7 @@ function getSourceMapFilePath(jsFilePath: string, options: CompilerOptions) {
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function getOutputExtension(fileName: string, options: CompilerOptions): Extension {
|
||||
export function getOutputExtension(fileName: string, options: Pick<CompilerOptions, "jsx">): Extension {
|
||||
return fileExtensionIs(fileName, Extension.Json) ? Extension.Json :
|
||||
options.jsx === JsxEmit.Preserve && fileExtensionIsOneOf(fileName, [Extension.Jsx, Extension.Tsx]) ? Extension.Jsx :
|
||||
fileExtensionIsOneOf(fileName, [Extension.Mts, Extension.Mjs]) ? Extension.Mjs :
|
||||
|
||||
@@ -303,6 +303,7 @@ export namespace Compiler {
|
||||
{ name: "noTypesAndSymbols", type: "boolean", defaultValueDescription: false },
|
||||
// Emitted js baseline will print full paths for every output file
|
||||
{ name: "fullEmitPaths", type: "boolean", defaultValueDescription: false },
|
||||
{ name: "reportDiagnostics", type: "boolean", defaultValueDescription: false }, // used to enable error collection in `transpile` baselines
|
||||
];
|
||||
|
||||
let optionsIndex: Map<string, ts.CommandLineOption>;
|
||||
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
} from "./_namespaces/Harness";
|
||||
import * as ts from "./_namespaces/ts";
|
||||
|
||||
export type TestRunnerKind = CompilerTestKind | FourslashTestKind | "project";
|
||||
export type TestRunnerKind = CompilerTestKind | FourslashTestKind | "project" | "transpile";
|
||||
export type CompilerTestKind = "conformance" | "compiler";
|
||||
export type FourslashTestKind = "fourslash" | "fourslash-server";
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
normalizePath,
|
||||
optionDeclarations,
|
||||
parseCustomTypeOption,
|
||||
ScriptTarget,
|
||||
toPath,
|
||||
transpileOptionValueCompilerOptions,
|
||||
} from "./_namespaces/ts";
|
||||
@@ -51,14 +52,64 @@ const optionsRedundantWithVerbatimModuleSyntax = new Set([
|
||||
|
||||
/*
|
||||
* This function will compile source text from 'input' argument using specified compiler options.
|
||||
* If not options are provided - it will use a set of default compiler options.
|
||||
* If no options are provided - it will use a set of default compiler options.
|
||||
* Extra compiler options that will unconditionally be used by this function are:
|
||||
* - isolatedModules = true
|
||||
* - allowNonTsExtensions = true
|
||||
* - noLib = true
|
||||
* - noResolve = true
|
||||
* - declaration = false
|
||||
*/
|
||||
export function transpileModule(input: string, transpileOptions: TranspileOptions): TranspileOutput {
|
||||
return transpileWorker(input, transpileOptions, /*declaration*/ false);
|
||||
}
|
||||
|
||||
/*
|
||||
* This function will create a declaration file from 'input' argument using specified compiler options.
|
||||
* If no options are provided - it will use a set of default compiler options.
|
||||
* Extra compiler options that will unconditionally be used by this function are:
|
||||
* - isolatedDeclarations = true
|
||||
* - isolatedModules = true
|
||||
* - allowNonTsExtensions = true
|
||||
* - noLib = true
|
||||
* - noResolve = true
|
||||
* - declaration = true
|
||||
* - emitDeclarationOnly = true
|
||||
* Note that this declaration file may differ from one produced by a full program typecheck,
|
||||
* in that only types in the single input file are available to be used in the generated declarations.
|
||||
*/
|
||||
export function transpileDeclaration(input: string, transpileOptions: TranspileOptions): TranspileOutput {
|
||||
return transpileWorker(input, transpileOptions, /*declaration*/ true);
|
||||
}
|
||||
|
||||
// Declaration emit works without a `lib`, but some local inferences you'd expect to work won't without
|
||||
// at least a minimal `lib` available, since the checker will `any` their types without these defined.
|
||||
// Late bound symbol names, in particular, are impossible to define without `Symbol` at least partially defined.
|
||||
// TODO: This should *probably* just load the full, real `lib` for the `target`.
|
||||
const barebonesLibContent = `/// <reference no-default-lib="true"/>
|
||||
interface Boolean {}
|
||||
interface Function {}
|
||||
interface CallableFunction {}
|
||||
interface NewableFunction {}
|
||||
interface IArguments {}
|
||||
interface Number {}
|
||||
interface Object {}
|
||||
interface RegExp {}
|
||||
interface String {}
|
||||
interface Array<T> { length: number; [n: number]: T; }
|
||||
interface SymbolConstructor {
|
||||
(desc?: string | number): symbol;
|
||||
for(name: string): symbol;
|
||||
readonly toStringTag: symbol;
|
||||
}
|
||||
declare var Symbol: SymbolConstructor;
|
||||
interface Symbol {
|
||||
readonly [Symbol.toStringTag]: string;
|
||||
}`;
|
||||
const barebonesLibName = "lib.d.ts";
|
||||
const barebonesLibSourceFile = createSourceFile(barebonesLibName, barebonesLibContent, { languageVersion: ScriptTarget.Latest });
|
||||
|
||||
function transpileWorker(input: string, transpileOptions: TranspileOptions, declaration?: boolean): TranspileOutput {
|
||||
const diagnostics: Diagnostic[] = [];
|
||||
|
||||
const options: CompilerOptions = transpileOptions.compilerOptions ? fixupCompilerOptions(transpileOptions.compilerOptions, diagnostics) : {};
|
||||
@@ -86,10 +137,19 @@ export function transpileModule(input: string, transpileOptions: TranspileOption
|
||||
// Filename can be non-ts file.
|
||||
options.allowNonTsExtensions = true;
|
||||
|
||||
if (declaration) {
|
||||
options.declaration = true;
|
||||
options.emitDeclarationOnly = true;
|
||||
options.isolatedDeclarations = true;
|
||||
}
|
||||
else {
|
||||
options.declaration = false;
|
||||
}
|
||||
|
||||
const newLine = getNewLineCharacter(options);
|
||||
// Create a compilerHost object to allow the compiler to read and write files
|
||||
const compilerHost: CompilerHost = {
|
||||
getSourceFile: fileName => fileName === normalizePath(inputFileName) ? sourceFile : undefined,
|
||||
getSourceFile: fileName => fileName === normalizePath(inputFileName) ? sourceFile : fileName === normalizePath(barebonesLibName) ? barebonesLibSourceFile : undefined,
|
||||
writeFile: (name, text) => {
|
||||
if (fileExtensionIs(name, ".map")) {
|
||||
Debug.assertEqual(sourceMapText, undefined, "Unexpected multiple source map outputs, file:", name);
|
||||
@@ -100,12 +160,12 @@ export function transpileModule(input: string, transpileOptions: TranspileOption
|
||||
outputText = text;
|
||||
}
|
||||
},
|
||||
getDefaultLibFileName: () => "lib.d.ts",
|
||||
getDefaultLibFileName: () => barebonesLibName,
|
||||
useCaseSensitiveFileNames: () => false,
|
||||
getCanonicalFileName: fileName => fileName,
|
||||
getCurrentDirectory: () => "",
|
||||
getNewLine: () => newLine,
|
||||
fileExists: (fileName): boolean => fileName === inputFileName,
|
||||
fileExists: (fileName): boolean => fileName === inputFileName || (!!declaration && fileName === barebonesLibName),
|
||||
readFile: () => "",
|
||||
directoryExists: () => true,
|
||||
getDirectories: () => [],
|
||||
@@ -135,14 +195,17 @@ export function transpileModule(input: string, transpileOptions: TranspileOption
|
||||
let outputText: string | undefined;
|
||||
let sourceMapText: string | undefined;
|
||||
|
||||
const program = createProgram([inputFileName], options, compilerHost);
|
||||
const inputs = declaration ? [inputFileName, barebonesLibName] : [inputFileName];
|
||||
const program = createProgram(inputs, options, compilerHost);
|
||||
|
||||
if (transpileOptions.reportDiagnostics) {
|
||||
addRange(/*to*/ diagnostics, /*from*/ program.getSyntacticDiagnostics(sourceFile));
|
||||
addRange(/*to*/ diagnostics, /*from*/ program.getOptionsDiagnostics());
|
||||
}
|
||||
// Emit
|
||||
program.emit(/*targetSourceFile*/ undefined, /*writeFile*/ undefined, /*cancellationToken*/ undefined, /*emitOnlyDtsFiles*/ undefined, transpileOptions.transformers);
|
||||
const result = program.emit(/*targetSourceFile*/ undefined, /*writeFile*/ undefined, /*cancellationToken*/ undefined, /*emitOnlyDtsFiles*/ declaration, transpileOptions.transformers, /*forceDtsEmit*/ declaration);
|
||||
|
||||
addRange(/*to*/ diagnostics, /*from*/ result.diagnostics);
|
||||
|
||||
if (outputText === undefined) return Debug.fail("Output generation failed");
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ export { Parallel };
|
||||
|
||||
export * from "../fourslashRunner";
|
||||
export * from "../compilerRunner";
|
||||
export * from "../transpileRunner";
|
||||
export * from "../runner";
|
||||
|
||||
// If running as emitted CJS, don't start executing the tests here; instead start in runner.ts.
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
setShardId,
|
||||
setShards,
|
||||
TestRunnerKind,
|
||||
TranspileRunner,
|
||||
} from "./_namespaces/Harness";
|
||||
import * as project from "./_namespaces/project";
|
||||
import * as ts from "./_namespaces/ts";
|
||||
@@ -66,6 +67,8 @@ export function createRunner(kind: TestRunnerKind): RunnerBase {
|
||||
return new FourSlashRunner(FourSlash.FourSlashTestType.Server);
|
||||
case "project":
|
||||
return new project.ProjectRunner();
|
||||
case "transpile":
|
||||
return new TranspileRunner();
|
||||
}
|
||||
return ts.Debug.fail(`Unknown runner kind ${kind}`);
|
||||
}
|
||||
@@ -190,6 +193,9 @@ function handleTestConfig() {
|
||||
case "fourslash-generated":
|
||||
runners.push(new GeneratedFourslashRunner(FourSlash.FourSlashTestType.Native));
|
||||
break;
|
||||
case "transpile":
|
||||
runners.push(new TranspileRunner());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -206,6 +212,9 @@ function handleTestConfig() {
|
||||
runners.push(new FourSlashRunner(FourSlash.FourSlashTestType.Native));
|
||||
runners.push(new FourSlashRunner(FourSlash.FourSlashTestType.Server));
|
||||
// runners.push(new GeneratedFourslashRunner());
|
||||
|
||||
// transpile
|
||||
runners.push(new TranspileRunner());
|
||||
}
|
||||
if (runUnitTests === undefined) {
|
||||
runUnitTests = runners.length !== 1; // Don't run unit tests when running only one runner if unit tests were not explicitly asked for
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
import {
|
||||
Baseline,
|
||||
Compiler,
|
||||
getFileBasedTestConfigurations,
|
||||
IO,
|
||||
RunnerBase,
|
||||
TestCaseParser,
|
||||
TestRunnerKind,
|
||||
} from "./_namespaces/Harness";
|
||||
import * as ts from "./_namespaces/ts";
|
||||
import * as vpath from "./_namespaces/vpath";
|
||||
|
||||
export class TranspileRunner extends RunnerBase {
|
||||
protected basePath = "tests/cases/transpile";
|
||||
protected testSuiteName: TestRunnerKind = "transpile";
|
||||
|
||||
public enumerateTestFiles() {
|
||||
// see also: `enumerateTestFiles` in tests/webTestServer.ts
|
||||
return this.enumerateFiles(this.basePath, /\.[cm]?[tj]sx?/i, { recursive: true });
|
||||
}
|
||||
|
||||
public kind() {
|
||||
return this.testSuiteName;
|
||||
}
|
||||
|
||||
public initializeTests() {
|
||||
if (this.tests.length === 0) {
|
||||
this.tests = IO.enumerateTestFiles(this);
|
||||
}
|
||||
|
||||
describe(this.testSuiteName + " tests", () => {
|
||||
this.tests.forEach(file => {
|
||||
file = vpath.normalizeSeparators(file);
|
||||
describe(file, () => {
|
||||
const tests = TranspileTestCase.getConfigurations(file);
|
||||
for (const test of tests) {
|
||||
test.run();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
enum TranspileKind {
|
||||
Module,
|
||||
Declaration,
|
||||
}
|
||||
|
||||
class TranspileTestCase {
|
||||
static varyBy = [];
|
||||
|
||||
static getConfigurations(file: string): TranspileTestCase[] {
|
||||
const ext = vpath.extname(file);
|
||||
const baseName = vpath.basename(file);
|
||||
const justName = baseName.slice(0, baseName.length - ext.length);
|
||||
const content = IO.readFile(file)!;
|
||||
const settings = TestCaseParser.extractCompilerSettings(content);
|
||||
const settingConfigurations = getFileBasedTestConfigurations(settings, TranspileTestCase.varyBy);
|
||||
return settingConfigurations?.map(c => {
|
||||
const desc = Object.entries(c).map(([key, value]) => `${key}=${value}`).join(",");
|
||||
return new TranspileTestCase(`${justName}(${desc})`, ext, content, { ...settings, ...c });
|
||||
}) ?? [new TranspileTestCase(justName, ext, content, settings)];
|
||||
}
|
||||
|
||||
private jsOutName;
|
||||
private dtsOutName;
|
||||
private units;
|
||||
constructor(
|
||||
private justName: string,
|
||||
private ext: string,
|
||||
private content: string,
|
||||
private settings: TestCaseParser.CompilerSettings,
|
||||
) {
|
||||
this.jsOutName = justName + this.getJsOutputExtension(`${justName}${ext}`);
|
||||
this.dtsOutName = justName + ts.getDeclarationEmitExtensionForPath(`${justName}${ext}`);
|
||||
this.units = TestCaseParser.makeUnitsFromTest(content, `${justName}${ext}`, settings);
|
||||
}
|
||||
|
||||
getJsOutputExtension(name: string) {
|
||||
return ts.getOutputExtension(name, { jsx: this.settings.jsx === "preserve" ? ts.JsxEmit.Preserve : undefined });
|
||||
}
|
||||
|
||||
runKind(kind: TranspileKind) {
|
||||
it(`transpile test ${this.justName} has expected ${kind === TranspileKind.Module ? "js" : "declaration"} output`, () => {
|
||||
let baselineText = "";
|
||||
|
||||
// include inputs in output so how the test is parsed and broken down is more obvious
|
||||
this.units.testUnitData.forEach(unit => {
|
||||
baselineText += `//// [${unit.name}] ////\r\n`;
|
||||
baselineText += unit.content;
|
||||
if (!unit.content.endsWith("\n")) {
|
||||
baselineText += "\r\n";
|
||||
}
|
||||
});
|
||||
|
||||
this.units.testUnitData.forEach(unit => {
|
||||
const opts: ts.CompilerOptions = {};
|
||||
Compiler.setCompilerOptionsFromHarnessSetting(this.settings, opts);
|
||||
const result = (kind === TranspileKind.Module ? ts.transpileModule : ts.transpileDeclaration)(unit.content, { compilerOptions: opts, fileName: unit.name, reportDiagnostics: this.settings.reportDiagnostics === "true" });
|
||||
|
||||
baselineText += `//// [${ts.changeExtension(unit.name, kind === TranspileKind.Module ? this.getJsOutputExtension(unit.name) : ts.getDeclarationEmitExtensionForPath(unit.name))}] ////\r\n`;
|
||||
baselineText += result.outputText;
|
||||
if (!result.outputText.endsWith("\n")) {
|
||||
baselineText += "\r\n";
|
||||
}
|
||||
if (result.diagnostics && result.diagnostics.length) {
|
||||
baselineText += "\r\n\r\n//// [Diagnostics reported]\r\n";
|
||||
baselineText += Compiler.getErrorBaseline([{ content: unit.content, unitName: unit.name }], result.diagnostics, !!opts.pretty);
|
||||
if (!baselineText.endsWith("\n")) {
|
||||
baselineText += "\r\n";
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Baseline.runBaseline(`transpile/${kind === TranspileKind.Module ? this.jsOutName : this.dtsOutName}`, baselineText);
|
||||
});
|
||||
}
|
||||
|
||||
run() {
|
||||
if (!this.settings.emitDeclarationOnly) {
|
||||
this.runKind(TranspileKind.Module);
|
||||
}
|
||||
if (this.settings.declaration) {
|
||||
this.runKind(TranspileKind.Declaration);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11190,6 +11190,7 @@ declare namespace ts {
|
||||
};
|
||||
function preProcessFile(sourceText: string, readImportFiles?: boolean, detectJavaScriptImports?: boolean): PreProcessedFileInfo;
|
||||
function transpileModule(input: string, transpileOptions: TranspileOptions): TranspileOutput;
|
||||
function transpileDeclaration(input: string, transpileOptions: TranspileOptions): TranspileOutput;
|
||||
function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[], moduleName?: string): string;
|
||||
interface TranspileOptions {
|
||||
compilerOptions?: CompilerOptions;
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
//// [variables.ts] ////
|
||||
export const a = 1;
|
||||
export let b = 2;
|
||||
export var c = 3;
|
||||
using d = undefined;
|
||||
export { d };
|
||||
await using e = undefined;
|
||||
export { e };
|
||||
//// [interface.ts] ////
|
||||
export interface Foo {
|
||||
a: string;
|
||||
readonly b: string;
|
||||
c?: string;
|
||||
}
|
||||
//// [class.ts] ////
|
||||
const i = Symbol();
|
||||
export class Bar {
|
||||
a: string;
|
||||
b?: string;
|
||||
declare c: string;
|
||||
#d: string;
|
||||
public e: string;
|
||||
protected f: string;
|
||||
private g: string;
|
||||
["h"]: string;
|
||||
[i]: string;
|
||||
}
|
||||
|
||||
export abstract class Baz {
|
||||
abstract a: string;
|
||||
abstract method(): void;
|
||||
}
|
||||
//// [namespace.ts] ////
|
||||
export namespace ns {
|
||||
namespace internal {
|
||||
export class Foo {}
|
||||
}
|
||||
export namespace nested {
|
||||
export import inner = internal;
|
||||
}
|
||||
}
|
||||
//// [alias.ts] ////
|
||||
export type A<T> = { x: T };
|
||||
//// [variables.d.ts] ////
|
||||
export declare const a = 1;
|
||||
export declare let b: number;
|
||||
export declare var c: number;
|
||||
declare const d: any;
|
||||
export { d };
|
||||
declare const e: any;
|
||||
export { e };
|
||||
//// [interface.d.ts] ////
|
||||
export interface Foo {
|
||||
a: string;
|
||||
readonly b: string;
|
||||
c?: string;
|
||||
}
|
||||
//// [class.d.ts] ////
|
||||
declare const i: unique symbol;
|
||||
export declare class Bar {
|
||||
#private;
|
||||
a: string;
|
||||
b?: string;
|
||||
c: string;
|
||||
e: string;
|
||||
protected f: string;
|
||||
private g;
|
||||
["h"]: string;
|
||||
[i]: string;
|
||||
}
|
||||
export declare abstract class Baz {
|
||||
abstract a: string;
|
||||
abstract method(): void;
|
||||
}
|
||||
export {};
|
||||
|
||||
|
||||
//// [Diagnostics reported]
|
||||
class.ts(1,7): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations.
|
||||
|
||||
|
||||
==== class.ts (1 errors) ====
|
||||
const i = Symbol();
|
||||
~
|
||||
!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations.
|
||||
!!! related TS9027 class.ts:1:7: Add a type annotation to the variable i.
|
||||
export class Bar {
|
||||
a: string;
|
||||
b?: string;
|
||||
declare c: string;
|
||||
#d: string;
|
||||
public e: string;
|
||||
protected f: string;
|
||||
private g: string;
|
||||
["h"]: string;
|
||||
[i]: string;
|
||||
}
|
||||
|
||||
export abstract class Baz {
|
||||
abstract a: string;
|
||||
abstract method(): void;
|
||||
}
|
||||
//// [namespace.d.ts] ////
|
||||
export declare namespace ns {
|
||||
namespace internal {
|
||||
class Foo {
|
||||
}
|
||||
}
|
||||
export namespace nested {
|
||||
export import inner = internal;
|
||||
}
|
||||
export {};
|
||||
}
|
||||
//// [alias.d.ts] ////
|
||||
export type A<T> = {
|
||||
x: T;
|
||||
};
|
||||
@@ -0,0 +1,138 @@
|
||||
//// [variables.ts] ////
|
||||
export const a = 1;
|
||||
export let b = 2;
|
||||
export var c = 3;
|
||||
using d = undefined;
|
||||
export { d };
|
||||
await using e = undefined;
|
||||
export { e };
|
||||
//// [interface.ts] ////
|
||||
export interface Foo {
|
||||
a: string;
|
||||
readonly b: string;
|
||||
c?: string;
|
||||
}
|
||||
//// [class.ts] ////
|
||||
const i = Symbol();
|
||||
export class Bar {
|
||||
a: string;
|
||||
b?: string;
|
||||
declare c: string;
|
||||
#d: string;
|
||||
public e: string;
|
||||
protected f: string;
|
||||
private g: string;
|
||||
["h"]: string;
|
||||
[i]: string;
|
||||
}
|
||||
|
||||
export abstract class Baz {
|
||||
abstract a: string;
|
||||
abstract method(): void;
|
||||
}
|
||||
//// [namespace.ts] ////
|
||||
export namespace ns {
|
||||
namespace internal {
|
||||
export class Foo {}
|
||||
}
|
||||
export namespace nested {
|
||||
export import inner = internal;
|
||||
}
|
||||
}
|
||||
//// [alias.ts] ////
|
||||
export type A<T> = { x: T };
|
||||
//// [variables.js] ////
|
||||
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
||||
if (value !== null && value !== void 0) {
|
||||
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
||||
var dispose;
|
||||
if (async) {
|
||||
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
||||
dispose = value[Symbol.asyncDispose];
|
||||
}
|
||||
if (dispose === void 0) {
|
||||
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
||||
dispose = value[Symbol.dispose];
|
||||
}
|
||||
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
||||
env.stack.push({ value: value, dispose: dispose, async: async });
|
||||
}
|
||||
else if (async) {
|
||||
env.stack.push({ async: true });
|
||||
}
|
||||
return value;
|
||||
};
|
||||
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
||||
return function (env) {
|
||||
function fail(e) {
|
||||
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
||||
env.hasError = true;
|
||||
}
|
||||
function next() {
|
||||
while (env.stack.length) {
|
||||
var rec = env.stack.pop();
|
||||
try {
|
||||
var result = rec.dispose && rec.dispose.call(rec.value);
|
||||
if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
||||
}
|
||||
catch (e) {
|
||||
fail(e);
|
||||
}
|
||||
}
|
||||
if (env.hasError) throw env.error;
|
||||
}
|
||||
return next();
|
||||
};
|
||||
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
||||
var e = new Error(message);
|
||||
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
||||
});
|
||||
export const a = 1;
|
||||
export let b = 2;
|
||||
export var c = 3;
|
||||
export { d };
|
||||
export { e };
|
||||
var d, e;
|
||||
const env_1 = { stack: [], error: void 0, hasError: false };
|
||||
try {
|
||||
d = __addDisposableResource(env_1, undefined, false);
|
||||
e = __addDisposableResource(env_1, undefined, true);
|
||||
}
|
||||
catch (e_1) {
|
||||
env_1.error = e_1;
|
||||
env_1.hasError = true;
|
||||
}
|
||||
finally {
|
||||
const result_1 = __disposeResources(env_1);
|
||||
if (result_1)
|
||||
await result_1;
|
||||
}
|
||||
//// [interface.js] ////
|
||||
export {};
|
||||
//// [class.js] ////
|
||||
var _Bar_d;
|
||||
const i = Symbol();
|
||||
export class Bar {
|
||||
constructor() {
|
||||
_Bar_d.set(this, void 0);
|
||||
}
|
||||
}
|
||||
_Bar_d = new WeakMap();
|
||||
export class Baz {
|
||||
}
|
||||
//// [namespace.js] ////
|
||||
export var ns;
|
||||
(function (ns) {
|
||||
let internal;
|
||||
(function (internal) {
|
||||
class Foo {
|
||||
}
|
||||
internal.Foo = Foo;
|
||||
})(internal || (internal = {}));
|
||||
let nested;
|
||||
(function (nested) {
|
||||
nested.inner = internal;
|
||||
})(nested = ns.nested || (ns.nested = {}));
|
||||
})(ns || (ns = {}));
|
||||
//// [alias.js] ////
|
||||
export {};
|
||||
@@ -0,0 +1,48 @@
|
||||
//// [defines.ts] ////
|
||||
export class A {
|
||||
field = { x: 1 }
|
||||
}
|
||||
//// [consumes.ts] ////
|
||||
import {A} from "./defines.js";
|
||||
export function create() {
|
||||
return new A();
|
||||
}
|
||||
//// [exposes.ts] ////
|
||||
import {create} from "./consumes.js";
|
||||
export const value = create();
|
||||
//// [defines.d.ts] ////
|
||||
export declare class A {
|
||||
field: {
|
||||
x: number;
|
||||
};
|
||||
}
|
||||
//// [consumes.d.ts] ////
|
||||
export declare function create(): any;
|
||||
|
||||
|
||||
//// [Diagnostics reported]
|
||||
consumes.ts(2,17): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations.
|
||||
|
||||
|
||||
==== consumes.ts (1 errors) ====
|
||||
import {A} from "./defines.js";
|
||||
export function create() {
|
||||
~~~~~~
|
||||
!!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations.
|
||||
!!! related TS9031 consumes.ts:2:17: Add a return type to the function declaration.
|
||||
return new A();
|
||||
}
|
||||
//// [exposes.d.ts] ////
|
||||
export declare const value: any;
|
||||
|
||||
|
||||
//// [Diagnostics reported]
|
||||
exposes.ts(2,14): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations.
|
||||
|
||||
|
||||
==== exposes.ts (1 errors) ====
|
||||
import {create} from "./consumes.js";
|
||||
export const value = create();
|
||||
~~~~~
|
||||
!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations.
|
||||
!!! related TS9027 exposes.ts:2:14: Add a type annotation to the variable value.
|
||||
@@ -0,0 +1,37 @@
|
||||
//// [defines.ts] ////
|
||||
export class A {
|
||||
field = { x: 1 }
|
||||
}
|
||||
//// [consumes.ts] ////
|
||||
import {A} from "./defines.js";
|
||||
export function create() {
|
||||
return new A();
|
||||
}
|
||||
//// [exposes.ts] ////
|
||||
import {create} from "./consumes.js";
|
||||
export const value = create();
|
||||
//// [defines.js] ////
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.A = void 0;
|
||||
var A = /** @class */ (function () {
|
||||
function A() {
|
||||
this.field = { x: 1 };
|
||||
}
|
||||
return A;
|
||||
}());
|
||||
exports.A = A;
|
||||
//// [consumes.js] ////
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.create = create;
|
||||
var defines_js_1 = require("./defines.js");
|
||||
function create() {
|
||||
return new defines_js_1.A();
|
||||
}
|
||||
//// [exposes.js] ////
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.value = void 0;
|
||||
var consumes_js_1 = require("./consumes.js");
|
||||
exports.value = (0, consumes_js_1.create)();
|
||||
@@ -0,0 +1,8 @@
|
||||
//// [declarationLinkedAliases.ts] ////
|
||||
import { A } from "mod";
|
||||
import B = A.C;
|
||||
export { B };
|
||||
//// [declarationLinkedAliases.d.ts] ////
|
||||
import { A } from "mod";
|
||||
import B = A.C;
|
||||
export { B };
|
||||
@@ -0,0 +1,11 @@
|
||||
//// [declarationLinkedAliases.ts] ////
|
||||
import { A } from "mod";
|
||||
import B = A.C;
|
||||
export { B };
|
||||
//// [declarationLinkedAliases.js] ////
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.B = void 0;
|
||||
var mod_1 = require("mod");
|
||||
var B = mod_1.A.C;
|
||||
exports.B = B;
|
||||
@@ -0,0 +1,15 @@
|
||||
//// [declarationSingleFileHasErrors.ts] ////
|
||||
export const a number = "missing colon";
|
||||
//// [declarationSingleFileHasErrors.d.ts] ////
|
||||
export declare const a: any, number = "missing colon";
|
||||
|
||||
|
||||
//// [Diagnostics reported]
|
||||
declarationSingleFileHasErrors.ts(1,14): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations.
|
||||
|
||||
|
||||
==== declarationSingleFileHasErrors.ts (1 errors) ====
|
||||
export const a number = "missing colon";
|
||||
~
|
||||
!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations.
|
||||
!!! related TS9027 declarationSingleFileHasErrors.ts:1:14: Add a type annotation to the variable a.
|
||||
@@ -0,0 +1,7 @@
|
||||
//// [declarationSingleFileHasErrors.ts] ////
|
||||
export const a number = "missing colon";
|
||||
//// [declarationSingleFileHasErrors.js] ////
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.number = exports.a = void 0;
|
||||
exports.number = "missing colon";
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
//// [declarationSingleFileHasErrorsReported.ts] ////
|
||||
export const a string = "missing colon";
|
||||
//// [declarationSingleFileHasErrorsReported.d.ts] ////
|
||||
export declare const a: any, string = "missing colon";
|
||||
|
||||
|
||||
//// [Diagnostics reported]
|
||||
declarationSingleFileHasErrorsReported.ts(1,14): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations.
|
||||
declarationSingleFileHasErrorsReported.ts(1,16): error TS1005: ',' expected.
|
||||
|
||||
|
||||
==== declarationSingleFileHasErrorsReported.ts (2 errors) ====
|
||||
export const a string = "missing colon";
|
||||
~
|
||||
!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations.
|
||||
!!! related TS9027 declarationSingleFileHasErrorsReported.ts:1:14: Add a type annotation to the variable a.
|
||||
~~~~~~
|
||||
!!! error TS1005: ',' expected.
|
||||
@@ -0,0 +1,17 @@
|
||||
//// [declarationSingleFileHasErrorsReported.ts] ////
|
||||
export const a string = "missing colon";
|
||||
//// [declarationSingleFileHasErrorsReported.js] ////
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.string = exports.a = void 0;
|
||||
exports.string = "missing colon";
|
||||
|
||||
|
||||
//// [Diagnostics reported]
|
||||
declarationSingleFileHasErrorsReported.ts(1,16): error TS1005: ',' expected.
|
||||
|
||||
|
||||
==== declarationSingleFileHasErrorsReported.ts (1 errors) ====
|
||||
export const a string = "missing colon";
|
||||
~~~~~~
|
||||
!!! error TS1005: ',' expected.
|
||||
@@ -0,0 +1,23 @@
|
||||
//// [declarationsSimple.ts] ////
|
||||
export const c: number = 1;
|
||||
|
||||
export interface A {
|
||||
x: number;
|
||||
}
|
||||
|
||||
let expr: { x: number; };
|
||||
|
||||
expr = {
|
||||
x: 12,
|
||||
}
|
||||
|
||||
export default expr;
|
||||
//// [declarationsSimple.d.ts] ////
|
||||
export declare const c: number;
|
||||
export interface A {
|
||||
x: number;
|
||||
}
|
||||
declare let expr: {
|
||||
x: number;
|
||||
};
|
||||
export default expr;
|
||||
@@ -0,0 +1,24 @@
|
||||
//// [declarationsSimple.ts] ////
|
||||
export const c: number = 1;
|
||||
|
||||
export interface A {
|
||||
x: number;
|
||||
}
|
||||
|
||||
let expr: { x: number; };
|
||||
|
||||
expr = {
|
||||
x: 12,
|
||||
}
|
||||
|
||||
export default expr;
|
||||
//// [declarationsSimple.js] ////
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.c = void 0;
|
||||
exports.c = 1;
|
||||
var expr;
|
||||
expr = {
|
||||
x: 12,
|
||||
};
|
||||
exports.default = expr;
|
||||
@@ -0,0 +1,45 @@
|
||||
// @declaration: true
|
||||
// @target: es6
|
||||
// @filename: variables.ts
|
||||
export const a = 1;
|
||||
export let b = 2;
|
||||
export var c = 3;
|
||||
using d = undefined;
|
||||
export { d };
|
||||
await using e = undefined;
|
||||
export { e };
|
||||
// @filename: interface.ts
|
||||
export interface Foo {
|
||||
a: string;
|
||||
readonly b: string;
|
||||
c?: string;
|
||||
}
|
||||
// @filename: class.ts
|
||||
const i = Symbol();
|
||||
export class Bar {
|
||||
a: string;
|
||||
b?: string;
|
||||
declare c: string;
|
||||
#d: string;
|
||||
public e: string;
|
||||
protected f: string;
|
||||
private g: string;
|
||||
["h"]: string;
|
||||
[i]: string;
|
||||
}
|
||||
|
||||
export abstract class Baz {
|
||||
abstract a: string;
|
||||
abstract method(): void;
|
||||
}
|
||||
// @filename: namespace.ts
|
||||
export namespace ns {
|
||||
namespace internal {
|
||||
export class Foo {}
|
||||
}
|
||||
export namespace nested {
|
||||
export import inner = internal;
|
||||
}
|
||||
}
|
||||
// @filename: alias.ts
|
||||
export type A<T> = { x: T };
|
||||
@@ -0,0 +1,13 @@
|
||||
// @declaration: true
|
||||
// @filename: defines.ts
|
||||
export class A {
|
||||
field = { x: 1 }
|
||||
}
|
||||
// @filename: consumes.ts
|
||||
import {A} from "./defines.js";
|
||||
export function create() {
|
||||
return new A();
|
||||
}
|
||||
// @filename: exposes.ts
|
||||
import {create} from "./consumes.js";
|
||||
export const value = create();
|
||||
@@ -0,0 +1,4 @@
|
||||
// @declaration: true
|
||||
import { A } from "mod";
|
||||
import B = A.C;
|
||||
export { B };
|
||||
@@ -0,0 +1,2 @@
|
||||
// @declaration: true
|
||||
export const a number = "missing colon";
|
||||
@@ -0,0 +1,3 @@
|
||||
// @declaration: true
|
||||
// @reportDiagnostics: true
|
||||
export const a string = "missing colon";
|
||||
@@ -0,0 +1,14 @@
|
||||
// @declaration: true
|
||||
export const c: number = 1;
|
||||
|
||||
export interface A {
|
||||
x: number;
|
||||
}
|
||||
|
||||
let expr: { x: number; };
|
||||
|
||||
expr = {
|
||||
x: 12,
|
||||
}
|
||||
|
||||
export default expr;
|
||||
Reference in New Issue
Block a user