mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Add generateTypesForModule to public API (#28069)
* Add generateTypesForModule to public API * Avoid parameter initializer and update baselines
This commit is contained in:
@@ -329,29 +329,7 @@ namespace FourSlash {
|
||||
});
|
||||
}
|
||||
|
||||
this.formatCodeSettings = {
|
||||
baseIndentSize: 0,
|
||||
indentSize: 4,
|
||||
tabSize: 4,
|
||||
newLineCharacter: "\n",
|
||||
convertTabsToSpaces: true,
|
||||
indentStyle: ts.IndentStyle.Smart,
|
||||
insertSpaceAfterCommaDelimiter: true,
|
||||
insertSpaceAfterSemicolonInForStatements: true,
|
||||
insertSpaceBeforeAndAfterBinaryOperators: true,
|
||||
insertSpaceAfterConstructor: false,
|
||||
insertSpaceAfterKeywordsInControlFlowStatements: true,
|
||||
insertSpaceAfterFunctionKeywordForAnonymousFunctions: false,
|
||||
insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: false,
|
||||
insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: false,
|
||||
insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces: true,
|
||||
insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: false,
|
||||
insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces: false,
|
||||
insertSpaceAfterTypeAssertion: false,
|
||||
placeOpenBraceOnNewLineForFunctions: false,
|
||||
placeOpenBraceOnNewLineForControlBlocks: false,
|
||||
insertSpaceBeforeTypeAnnotation: false
|
||||
};
|
||||
this.formatCodeSettings = ts.testFormatSettings;
|
||||
|
||||
// Open the first file by default
|
||||
this.openFile(0);
|
||||
@@ -3389,8 +3367,8 @@ Actual: ${stringify(fullActual)}`);
|
||||
}
|
||||
|
||||
public generateTypes(examples: ReadonlyArray<FourSlashInterface.GenerateTypesOptions>): void {
|
||||
for (const { name = "example", value, output, outputBaseline } of examples) {
|
||||
const actual = ts.generateTypesForModule(name, value, this.formatCodeSettings);
|
||||
for (const { name = "example", value, global, output, outputBaseline } of examples) {
|
||||
const actual = (global ? ts.generateTypesForGlobal : ts.generateTypesForModule)(name, value, this.formatCodeSettings);
|
||||
if (outputBaseline) {
|
||||
if (actual === undefined) throw ts.Debug.fail();
|
||||
Harness.Baseline.runBaseline(ts.combinePaths("generateTypes", outputBaseline + ts.Extension.Dts), actual);
|
||||
@@ -4536,6 +4514,7 @@ namespace FourSlashInterface {
|
||||
export interface GenerateTypesOptions {
|
||||
readonly name?: string;
|
||||
readonly value: unknown;
|
||||
readonly global?: boolean;
|
||||
// Exactly one of these should be set:
|
||||
readonly output?: string;
|
||||
readonly outputBaseline?: string;
|
||||
@@ -4689,7 +4668,7 @@ namespace FourSlashInterface {
|
||||
}
|
||||
|
||||
public setOption(name: keyof ts.FormatCodeSettings, value: number | string | boolean): void {
|
||||
this.state.formatCodeSettings[name] = value;
|
||||
this.state.formatCodeSettings = { ...this.state.formatCodeSettings, [name]: value };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -561,7 +561,7 @@ namespace ts.server {
|
||||
this.typingsCache = new TypingsCache(this.typingsInstaller);
|
||||
|
||||
this.hostConfiguration = {
|
||||
formatCodeOptions: getDefaultFormatCodeSettings(this.host),
|
||||
formatCodeOptions: getDefaultFormatCodeSettings(this.host.newLine),
|
||||
preferences: emptyOptions,
|
||||
hostInfo: "Unknown host",
|
||||
extraFileExtensions: []
|
||||
|
||||
@@ -438,7 +438,7 @@ namespace ts.server {
|
||||
setOptions(formatSettings: FormatCodeSettings, preferences: protocol.UserPreferences | undefined): void {
|
||||
if (formatSettings) {
|
||||
if (!this.formatSettings) {
|
||||
this.formatSettings = getDefaultFormatCodeSettings(this.host);
|
||||
this.formatSettings = getDefaultFormatCodeSettings(this.host.newLine);
|
||||
assign(this.formatSettings, formatSettings);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -56,30 +56,6 @@ namespace ts.server {
|
||||
}
|
||||
}
|
||||
|
||||
export function getDefaultFormatCodeSettings(host: ServerHost): FormatCodeSettings {
|
||||
return {
|
||||
indentSize: 4,
|
||||
tabSize: 4,
|
||||
newLineCharacter: host.newLine || "\n",
|
||||
convertTabsToSpaces: true,
|
||||
indentStyle: IndentStyle.Smart,
|
||||
insertSpaceAfterConstructor: false,
|
||||
insertSpaceAfterCommaDelimiter: true,
|
||||
insertSpaceAfterSemicolonInForStatements: true,
|
||||
insertSpaceBeforeAndAfterBinaryOperators: true,
|
||||
insertSpaceAfterKeywordsInControlFlowStatements: true,
|
||||
insertSpaceAfterFunctionKeywordForAnonymousFunctions: false,
|
||||
insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: false,
|
||||
insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: false,
|
||||
insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces: true,
|
||||
insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: false,
|
||||
insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces: false,
|
||||
insertSpaceBeforeFunctionParenthesis: false,
|
||||
placeOpenBraceOnNewLineForFunctions: false,
|
||||
placeOpenBraceOnNewLineForControlBlocks: false,
|
||||
};
|
||||
}
|
||||
|
||||
export type NormalizedPath = string & { __normalizedPathTag: any };
|
||||
|
||||
export function toNormalizedPath(fileName: string): NormalizedPath {
|
||||
|
||||
@@ -1,14 +1,22 @@
|
||||
/* @internal */
|
||||
namespace ts {
|
||||
export function generateTypesForModule(name: string, moduleValue: unknown, formatSettings: FormatCodeSettings): string {
|
||||
return valueInfoToDeclarationFileText(inspectValue(name, moduleValue), formatSettings);
|
||||
return generateTypesForModuleOrGlobal(name, moduleValue, formatSettings, OutputKind.ExportEquals);
|
||||
}
|
||||
|
||||
export function valueInfoToDeclarationFileText(valueInfo: ValueInfo, formatSettings: FormatCodeSettings): string {
|
||||
return textChanges.getNewFileText(toStatements(valueInfo, OutputKind.ExportEquals), ScriptKind.TS, "\n", formatting.getFormatContext(formatSettings));
|
||||
export function generateTypesForGlobal(name: string, globalValue: unknown, formatSettings: FormatCodeSettings): string {
|
||||
return generateTypesForModuleOrGlobal(name, globalValue, formatSettings, OutputKind.Global);
|
||||
}
|
||||
|
||||
const enum OutputKind { ExportEquals, NamedExport, NamespaceMember }
|
||||
function generateTypesForModuleOrGlobal(name: string, globalValue: unknown, formatSettings: FormatCodeSettings, outputKind: OutputKind.ExportEquals | OutputKind.Global): string {
|
||||
return valueInfoToDeclarationFileText(inspectValue(name, globalValue), formatSettings, outputKind);
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
export function valueInfoToDeclarationFileText(valueInfo: ValueInfo, formatSettings: FormatCodeSettings, outputKind: OutputKind.ExportEquals | OutputKind.Global = OutputKind.ExportEquals): string {
|
||||
return textChanges.getNewFileText(toStatements(valueInfo, outputKind), ScriptKind.TS, formatSettings.newLineCharacter || "\n", formatting.getFormatContext(formatSettings));
|
||||
}
|
||||
|
||||
const enum OutputKind { ExportEquals, NamedExport, NamespaceMember, Global }
|
||||
function toNamespaceMemberStatements(info: ValueInfo): ReadonlyArray<Statement> {
|
||||
return toStatements(info, OutputKind.NamespaceMember);
|
||||
}
|
||||
@@ -18,7 +26,7 @@ namespace ts {
|
||||
if (!isValidIdentifier(name) || isDefault && kind !== OutputKind.NamedExport) return emptyArray;
|
||||
|
||||
const modifiers = isDefault && info.kind === ValueKind.FunctionOrClass ? [createModifier(SyntaxKind.ExportKeyword), createModifier(SyntaxKind.DefaultKeyword)]
|
||||
: kind === OutputKind.ExportEquals ? [createModifier(SyntaxKind.DeclareKeyword)]
|
||||
: kind === OutputKind.Global || kind === OutputKind.ExportEquals ? [createModifier(SyntaxKind.DeclareKeyword)]
|
||||
: kind === OutputKind.NamedExport ? [createModifier(SyntaxKind.ExportKeyword)]
|
||||
: undefined;
|
||||
const exportEquals = () => kind === OutputKind.ExportEquals ? [exportEqualsOrDefault(info.name, /*isExportEquals*/ true)] : emptyArray;
|
||||
@@ -132,11 +140,14 @@ namespace ts {
|
||||
case ValueKind.FunctionOrClass:
|
||||
return createTypeReferenceNode("Function", /*typeArguments*/ undefined); // Normally we create a FunctionDeclaration, but this can happen for a function in an array.
|
||||
case ValueKind.Object:
|
||||
return createTypeLiteralNode(info.members.map(m => createPropertySignature(/*modifiers*/ undefined, m.name, /*questionToken*/ undefined, toType(m), /*initializer*/ undefined)));
|
||||
return createTypeLiteralNode(info.members.map(m => createPropertySignature(/*modifiers*/ undefined, toPropertyName(m.name), /*questionToken*/ undefined, toType(m), /*initializer*/ undefined)));
|
||||
default:
|
||||
return Debug.assertNever(info);
|
||||
}
|
||||
}
|
||||
function toPropertyName(name: string): Identifier | StringLiteral {
|
||||
return isIdentifierText(name, ScriptTarget.ESNext) ? createIdentifier(name) : createStringLiteral(name);
|
||||
}
|
||||
|
||||
// Parses assignments to "this.x" in the constructor into class property declarations
|
||||
function getConstructorFunctionInstanceProperties(fnAst: FunctionOrConstructorNode): ReadonlyArray<PropertyDeclaration> {
|
||||
|
||||
@@ -816,7 +816,7 @@ namespace ts.textChanges {
|
||||
const nonFormattedText = statements.map(s => getNonformattedText(s, oldFile, newLineCharacter).text).join(newLineCharacter);
|
||||
const sourceFile = createSourceFile("any file name", nonFormattedText, ScriptTarget.ESNext, /*setParentNodes*/ true, scriptKind);
|
||||
const changes = formatting.formatDocument(sourceFile, formatContext);
|
||||
return applyChanges(nonFormattedText, changes);
|
||||
return applyChanges(nonFormattedText, changes) + newLineCharacter;
|
||||
}
|
||||
|
||||
function computeNewText(change: Change, sourceFile: SourceFile, newLineCharacter: string, formatContext: formatting.FormatContext, validate: ValidateNonFormattedText | undefined): string {
|
||||
|
||||
+42
-40
@@ -712,49 +712,51 @@ namespace ts {
|
||||
}
|
||||
|
||||
export interface FormatCodeSettings extends EditorSettings {
|
||||
insertSpaceAfterCommaDelimiter?: boolean;
|
||||
insertSpaceAfterSemicolonInForStatements?: boolean;
|
||||
insertSpaceBeforeAndAfterBinaryOperators?: boolean;
|
||||
insertSpaceAfterConstructor?: boolean;
|
||||
insertSpaceAfterKeywordsInControlFlowStatements?: boolean;
|
||||
insertSpaceAfterFunctionKeywordForAnonymousFunctions?: boolean;
|
||||
insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis?: boolean;
|
||||
insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets?: boolean;
|
||||
insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces?: boolean;
|
||||
insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces?: boolean;
|
||||
insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces?: boolean;
|
||||
insertSpaceAfterTypeAssertion?: boolean;
|
||||
insertSpaceBeforeFunctionParenthesis?: boolean;
|
||||
placeOpenBraceOnNewLineForFunctions?: boolean;
|
||||
placeOpenBraceOnNewLineForControlBlocks?: boolean;
|
||||
insertSpaceBeforeTypeAnnotation?: boolean;
|
||||
indentMultiLineObjectLiteralBeginningOnBlankLine?: boolean;
|
||||
readonly insertSpaceAfterCommaDelimiter?: boolean;
|
||||
readonly insertSpaceAfterSemicolonInForStatements?: boolean;
|
||||
readonly insertSpaceBeforeAndAfterBinaryOperators?: boolean;
|
||||
readonly insertSpaceAfterConstructor?: boolean;
|
||||
readonly insertSpaceAfterKeywordsInControlFlowStatements?: boolean;
|
||||
readonly insertSpaceAfterFunctionKeywordForAnonymousFunctions?: boolean;
|
||||
readonly insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis?: boolean;
|
||||
readonly insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets?: boolean;
|
||||
readonly insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces?: boolean;
|
||||
readonly insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces?: boolean;
|
||||
readonly insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces?: boolean;
|
||||
readonly insertSpaceAfterTypeAssertion?: boolean;
|
||||
readonly insertSpaceBeforeFunctionParenthesis?: boolean;
|
||||
readonly placeOpenBraceOnNewLineForFunctions?: boolean;
|
||||
readonly placeOpenBraceOnNewLineForControlBlocks?: boolean;
|
||||
readonly insertSpaceBeforeTypeAnnotation?: boolean;
|
||||
readonly indentMultiLineObjectLiteralBeginningOnBlankLine?: boolean;
|
||||
}
|
||||
|
||||
export function getDefaultFormatCodeSettings(newLineCharacter?: string): FormatCodeSettings {
|
||||
return {
|
||||
indentSize: 4,
|
||||
tabSize: 4,
|
||||
newLineCharacter: newLineCharacter || "\n",
|
||||
convertTabsToSpaces: true,
|
||||
indentStyle: IndentStyle.Smart,
|
||||
insertSpaceAfterConstructor: false,
|
||||
insertSpaceAfterCommaDelimiter: true,
|
||||
insertSpaceAfterSemicolonInForStatements: true,
|
||||
insertSpaceBeforeAndAfterBinaryOperators: true,
|
||||
insertSpaceAfterKeywordsInControlFlowStatements: true,
|
||||
insertSpaceAfterFunctionKeywordForAnonymousFunctions: false,
|
||||
insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: false,
|
||||
insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: false,
|
||||
insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces: true,
|
||||
insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: false,
|
||||
insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces: false,
|
||||
insertSpaceBeforeFunctionParenthesis: false,
|
||||
placeOpenBraceOnNewLineForFunctions: false,
|
||||
placeOpenBraceOnNewLineForControlBlocks: false,
|
||||
};
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
export const testFormatSettings: FormatCodeSettings = {
|
||||
baseIndentSize: 0,
|
||||
indentSize: 4,
|
||||
tabSize: 4,
|
||||
newLineCharacter: "\n",
|
||||
convertTabsToSpaces: true,
|
||||
indentStyle: IndentStyle.Smart,
|
||||
insertSpaceAfterCommaDelimiter: true,
|
||||
insertSpaceAfterSemicolonInForStatements: true,
|
||||
insertSpaceBeforeAndAfterBinaryOperators: true,
|
||||
insertSpaceAfterConstructor: false,
|
||||
insertSpaceAfterKeywordsInControlFlowStatements: true,
|
||||
insertSpaceAfterFunctionKeywordForAnonymousFunctions: false,
|
||||
insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: false,
|
||||
insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: false,
|
||||
insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces: true,
|
||||
insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: false,
|
||||
insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces: false,
|
||||
insertSpaceAfterTypeAssertion: false,
|
||||
placeOpenBraceOnNewLineForFunctions: false,
|
||||
placeOpenBraceOnNewLineForControlBlocks: false,
|
||||
insertSpaceBeforeTypeAnnotation: false
|
||||
};
|
||||
export const testFormatSettings = getDefaultFormatCodeSettings("\n");
|
||||
|
||||
export interface DefinitionInfo extends DocumentSpan {
|
||||
kind: ScriptElementKind;
|
||||
|
||||
@@ -4497,8 +4497,7 @@ namespace ts.projectSystem {
|
||||
const defaultSettings = projectService.getFormatCodeOptions(f1.path as server.NormalizedPath);
|
||||
|
||||
// set global settings
|
||||
const newGlobalSettings1 = clone(defaultSettings);
|
||||
newGlobalSettings1.placeOpenBraceOnNewLineForControlBlocks = !newGlobalSettings1.placeOpenBraceOnNewLineForControlBlocks;
|
||||
const newGlobalSettings1 = { ...defaultSettings, placeOpenBraceOnNewLineForControlBlocks: !defaultSettings.placeOpenBraceOnNewLineForControlBlocks };
|
||||
projectService.setHostConfiguration({ formatOptions: newGlobalSettings1 });
|
||||
|
||||
// get format options for file - should be equal to new global settings
|
||||
@@ -4506,8 +4505,7 @@ namespace ts.projectSystem {
|
||||
assert.deepEqual(s1, newGlobalSettings1, "file settings should be the same with global settings");
|
||||
|
||||
// set per file format options
|
||||
const newPerFileSettings = clone(defaultSettings);
|
||||
newPerFileSettings.insertSpaceAfterCommaDelimiter = !newPerFileSettings.insertSpaceAfterCommaDelimiter;
|
||||
const newPerFileSettings = { ...defaultSettings, insertSpaceAfterCommaDelimiter: !defaultSettings.insertSpaceAfterCommaDelimiter };
|
||||
projectService.setHostConfiguration({ formatOptions: newPerFileSettings, file: f1.path });
|
||||
|
||||
// get format options for file - should be equal to new per-file settings
|
||||
@@ -4515,8 +4513,7 @@ namespace ts.projectSystem {
|
||||
assert.deepEqual(s2, newPerFileSettings, "file settings should be the same with per-file settings");
|
||||
|
||||
// set new global settings - they should not affect ones that were set per-file
|
||||
const newGlobalSettings2 = clone(defaultSettings);
|
||||
newGlobalSettings2.insertSpaceAfterSemicolonInForStatements = !newGlobalSettings2.insertSpaceAfterSemicolonInForStatements;
|
||||
const newGlobalSettings2 = { ...defaultSettings, insertSpaceAfterSemicolonInForStatements: !defaultSettings.insertSpaceAfterSemicolonInForStatements };
|
||||
projectService.setHostConfiguration({ formatOptions: newGlobalSettings2 });
|
||||
|
||||
// get format options for file - should be equal to new per-file settings
|
||||
@@ -6837,7 +6834,7 @@ namespace ts.projectSystem {
|
||||
{
|
||||
start: { line: 0, offset: 0 },
|
||||
end: { line: 0, offset: 0 },
|
||||
newText: "export const a = 0;",
|
||||
newText: "export const a = 0;\n",
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
+22
-18
@@ -5042,24 +5042,25 @@ declare namespace ts {
|
||||
insertSpaceBeforeTypeAnnotation?: boolean;
|
||||
}
|
||||
interface FormatCodeSettings extends EditorSettings {
|
||||
insertSpaceAfterCommaDelimiter?: boolean;
|
||||
insertSpaceAfterSemicolonInForStatements?: boolean;
|
||||
insertSpaceBeforeAndAfterBinaryOperators?: boolean;
|
||||
insertSpaceAfterConstructor?: boolean;
|
||||
insertSpaceAfterKeywordsInControlFlowStatements?: boolean;
|
||||
insertSpaceAfterFunctionKeywordForAnonymousFunctions?: boolean;
|
||||
insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis?: boolean;
|
||||
insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets?: boolean;
|
||||
insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces?: boolean;
|
||||
insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces?: boolean;
|
||||
insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces?: boolean;
|
||||
insertSpaceAfterTypeAssertion?: boolean;
|
||||
insertSpaceBeforeFunctionParenthesis?: boolean;
|
||||
placeOpenBraceOnNewLineForFunctions?: boolean;
|
||||
placeOpenBraceOnNewLineForControlBlocks?: boolean;
|
||||
insertSpaceBeforeTypeAnnotation?: boolean;
|
||||
indentMultiLineObjectLiteralBeginningOnBlankLine?: boolean;
|
||||
readonly insertSpaceAfterCommaDelimiter?: boolean;
|
||||
readonly insertSpaceAfterSemicolonInForStatements?: boolean;
|
||||
readonly insertSpaceBeforeAndAfterBinaryOperators?: boolean;
|
||||
readonly insertSpaceAfterConstructor?: boolean;
|
||||
readonly insertSpaceAfterKeywordsInControlFlowStatements?: boolean;
|
||||
readonly insertSpaceAfterFunctionKeywordForAnonymousFunctions?: boolean;
|
||||
readonly insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis?: boolean;
|
||||
readonly insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets?: boolean;
|
||||
readonly insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces?: boolean;
|
||||
readonly insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces?: boolean;
|
||||
readonly insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces?: boolean;
|
||||
readonly insertSpaceAfterTypeAssertion?: boolean;
|
||||
readonly insertSpaceBeforeFunctionParenthesis?: boolean;
|
||||
readonly placeOpenBraceOnNewLineForFunctions?: boolean;
|
||||
readonly placeOpenBraceOnNewLineForControlBlocks?: boolean;
|
||||
readonly insertSpaceBeforeTypeAnnotation?: boolean;
|
||||
readonly indentMultiLineObjectLiteralBeginningOnBlankLine?: boolean;
|
||||
}
|
||||
function getDefaultFormatCodeSettings(newLineCharacter?: string): FormatCodeSettings;
|
||||
interface DefinitionInfo extends DocumentSpan {
|
||||
kind: ScriptElementKind;
|
||||
name: string;
|
||||
@@ -5508,6 +5509,10 @@ declare namespace ts {
|
||||
function transpileModule(input: string, transpileOptions: TranspileOptions): TranspileOutput;
|
||||
function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[], moduleName?: string): string;
|
||||
}
|
||||
declare namespace ts {
|
||||
function generateTypesForModule(name: string, moduleValue: unknown, formatSettings: FormatCodeSettings): string;
|
||||
function generateTypesForGlobal(name: string, globalValue: unknown, formatSettings: FormatCodeSettings): string;
|
||||
}
|
||||
declare namespace ts {
|
||||
/** The version of the language service API */
|
||||
const servicesVersion = "0.8";
|
||||
@@ -5597,7 +5602,6 @@ declare namespace ts.server {
|
||||
function ThrowProjectLanguageServiceDisabled(): never;
|
||||
function ThrowProjectDoesNotContainDocument(fileName: string, project: Project): never;
|
||||
}
|
||||
function getDefaultFormatCodeSettings(host: ServerHost): FormatCodeSettings;
|
||||
type NormalizedPath = string & {
|
||||
__normalizedPathTag: any;
|
||||
};
|
||||
|
||||
+22
-17
@@ -5042,24 +5042,25 @@ declare namespace ts {
|
||||
insertSpaceBeforeTypeAnnotation?: boolean;
|
||||
}
|
||||
interface FormatCodeSettings extends EditorSettings {
|
||||
insertSpaceAfterCommaDelimiter?: boolean;
|
||||
insertSpaceAfterSemicolonInForStatements?: boolean;
|
||||
insertSpaceBeforeAndAfterBinaryOperators?: boolean;
|
||||
insertSpaceAfterConstructor?: boolean;
|
||||
insertSpaceAfterKeywordsInControlFlowStatements?: boolean;
|
||||
insertSpaceAfterFunctionKeywordForAnonymousFunctions?: boolean;
|
||||
insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis?: boolean;
|
||||
insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets?: boolean;
|
||||
insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces?: boolean;
|
||||
insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces?: boolean;
|
||||
insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces?: boolean;
|
||||
insertSpaceAfterTypeAssertion?: boolean;
|
||||
insertSpaceBeforeFunctionParenthesis?: boolean;
|
||||
placeOpenBraceOnNewLineForFunctions?: boolean;
|
||||
placeOpenBraceOnNewLineForControlBlocks?: boolean;
|
||||
insertSpaceBeforeTypeAnnotation?: boolean;
|
||||
indentMultiLineObjectLiteralBeginningOnBlankLine?: boolean;
|
||||
readonly insertSpaceAfterCommaDelimiter?: boolean;
|
||||
readonly insertSpaceAfterSemicolonInForStatements?: boolean;
|
||||
readonly insertSpaceBeforeAndAfterBinaryOperators?: boolean;
|
||||
readonly insertSpaceAfterConstructor?: boolean;
|
||||
readonly insertSpaceAfterKeywordsInControlFlowStatements?: boolean;
|
||||
readonly insertSpaceAfterFunctionKeywordForAnonymousFunctions?: boolean;
|
||||
readonly insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis?: boolean;
|
||||
readonly insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets?: boolean;
|
||||
readonly insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces?: boolean;
|
||||
readonly insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces?: boolean;
|
||||
readonly insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces?: boolean;
|
||||
readonly insertSpaceAfterTypeAssertion?: boolean;
|
||||
readonly insertSpaceBeforeFunctionParenthesis?: boolean;
|
||||
readonly placeOpenBraceOnNewLineForFunctions?: boolean;
|
||||
readonly placeOpenBraceOnNewLineForControlBlocks?: boolean;
|
||||
readonly insertSpaceBeforeTypeAnnotation?: boolean;
|
||||
readonly indentMultiLineObjectLiteralBeginningOnBlankLine?: boolean;
|
||||
}
|
||||
function getDefaultFormatCodeSettings(newLineCharacter?: string): FormatCodeSettings;
|
||||
interface DefinitionInfo extends DocumentSpan {
|
||||
kind: ScriptElementKind;
|
||||
name: string;
|
||||
@@ -5508,6 +5509,10 @@ declare namespace ts {
|
||||
function transpileModule(input: string, transpileOptions: TranspileOptions): TranspileOutput;
|
||||
function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[], moduleName?: string): string;
|
||||
}
|
||||
declare namespace ts {
|
||||
function generateTypesForModule(name: string, moduleValue: unknown, formatSettings: FormatCodeSettings): string;
|
||||
function generateTypesForGlobal(name: string, globalValue: unknown, formatSettings: FormatCodeSettings): string;
|
||||
}
|
||||
declare namespace ts {
|
||||
/** The version of the language service API */
|
||||
const servicesVersion = "0.8";
|
||||
|
||||
+1
-1
@@ -233,4 +233,4 @@ export class Symbol {
|
||||
static toStringTag: symbol;
|
||||
static unscopables: symbol;
|
||||
valueOf(): any;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -665,4 +665,4 @@ declare namespace example {
|
||||
// Circular reference from example.partialRight
|
||||
const placeholder: any;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -642,6 +642,7 @@ declare namespace FourSlashInterface {
|
||||
interface GenerateTypesOptions {
|
||||
readonly name?: string;
|
||||
readonly value: unknown;
|
||||
readonly global?: boolean;
|
||||
readonly output?: string | undefined;
|
||||
readonly outputBaseline?: string;
|
||||
}
|
||||
|
||||
@@ -3,17 +3,56 @@
|
||||
////dummy text
|
||||
|
||||
verify.generateTypes(
|
||||
{
|
||||
value: 0,
|
||||
global: true,
|
||||
output: "declare const example: number;\n",
|
||||
},
|
||||
{
|
||||
value: { x: 0, f() {} },
|
||||
global: true,
|
||||
output:
|
||||
`declare namespace example {
|
||||
function f(): void;
|
||||
const x: number;
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
value: { "*": 10, "default": true, "with": 10, " ": 3 },
|
||||
global: true,
|
||||
output:
|
||||
`declare const example: {
|
||||
" ": number;
|
||||
"*": number;
|
||||
default: boolean;
|
||||
with: number;
|
||||
};
|
||||
`,
|
||||
},
|
||||
{
|
||||
value: { "*": 10, f() {} },
|
||||
global: true,
|
||||
output:
|
||||
`declare namespace example {
|
||||
function f(): void;
|
||||
}
|
||||
`,
|
||||
},
|
||||
|
||||
{
|
||||
value: 0,
|
||||
output:
|
||||
`export = example;
|
||||
declare const example: number;`,
|
||||
declare const example: number;
|
||||
`,
|
||||
},
|
||||
{
|
||||
value: (x, y) => x + y,
|
||||
output:
|
||||
`export = example;
|
||||
declare function example(x: any, y: any): void;`,
|
||||
declare function example(x: any, y: any): void;
|
||||
`,
|
||||
},
|
||||
{
|
||||
// non-arrow functions have different toString(), so important to test
|
||||
@@ -25,46 +64,53 @@ declare function example(x: any, y: any): void;`,
|
||||
},
|
||||
output:
|
||||
`export = example;
|
||||
declare function example(x: any, y: any): any;`,
|
||||
declare function example(x: any, y: any): any;
|
||||
`,
|
||||
},
|
||||
{
|
||||
value: function(x) { arguments; },
|
||||
output:
|
||||
`export = example;
|
||||
declare function example(x: any, ...args: any[]): void;`,
|
||||
declare function example(x: any, ...args: any[]): void;
|
||||
`,
|
||||
},
|
||||
|
||||
{
|
||||
value: ({ default() {} }),
|
||||
output:
|
||||
`export default function _default(): void;`,
|
||||
`export default function _default(): void;
|
||||
`,
|
||||
},
|
||||
|
||||
{
|
||||
value: ({ default: class {} }),
|
||||
output:
|
||||
`export default class _default {
|
||||
}`,
|
||||
}
|
||||
`,
|
||||
},
|
||||
|
||||
{
|
||||
value: new Date(),
|
||||
output:
|
||||
`export = example;
|
||||
declare const example: Date;`,
|
||||
declare const example: Date;
|
||||
`,
|
||||
},
|
||||
|
||||
{
|
||||
value: [0],
|
||||
output:
|
||||
`export = example;
|
||||
declare const example: number[];`,
|
||||
declare const example: number[];
|
||||
`,
|
||||
},
|
||||
{
|
||||
value: [() => 0, () => ""],
|
||||
output:
|
||||
`export = example;
|
||||
declare const example: Function[];`,
|
||||
declare const example: Function[];
|
||||
`,
|
||||
},
|
||||
{
|
||||
value: (() => {
|
||||
@@ -74,7 +120,8 @@ declare const example: Function[];`,
|
||||
})(),
|
||||
output:
|
||||
`export = example;
|
||||
declare const example: any[];`,
|
||||
declare const example: any[];
|
||||
`,
|
||||
},
|
||||
{
|
||||
value: (() => {
|
||||
@@ -104,6 +151,7 @@ export namespace ns2 {
|
||||
function fn(x: any): void;
|
||||
}
|
||||
// Circular reference from example
|
||||
export const self: any;`,
|
||||
export const self: any;
|
||||
`,
|
||||
},
|
||||
);
|
||||
|
||||
@@ -8,7 +8,8 @@ verify.generateTypes(
|
||||
output:
|
||||
`export = example;
|
||||
declare class example {
|
||||
}`,
|
||||
}
|
||||
`,
|
||||
},
|
||||
|
||||
{
|
||||
@@ -28,11 +29,13 @@ declare class example {
|
||||
declare class example {
|
||||
constructor(x: any);
|
||||
x: any;
|
||||
}`,
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
value: { x: 0, export: 0 },
|
||||
output: `export const x: number;`,
|
||||
output: `export const x: number;
|
||||
`,
|
||||
},
|
||||
{
|
||||
value: (() => {
|
||||
@@ -87,7 +90,8 @@ declare namespace example {
|
||||
namespace staticMethod {
|
||||
const staticMethodProperty: number;
|
||||
}
|
||||
}`,
|
||||
}
|
||||
`,
|
||||
},
|
||||
|
||||
{
|
||||
@@ -103,7 +107,8 @@ declare class example {
|
||||
static staticMethod(): void;
|
||||
x: any;
|
||||
method(): void;
|
||||
}`,
|
||||
}
|
||||
`,
|
||||
},
|
||||
|
||||
);
|
||||
|
||||
@@ -23,7 +23,8 @@ a; y;`,
|
||||
"/y.ts":
|
||||
`import { b } from './other';
|
||||
import { p } from './a';
|
||||
export const y: Date = p + b;`,
|
||||
export const y: Date = p + b;
|
||||
`,
|
||||
},
|
||||
|
||||
preferences: {
|
||||
|
||||
@@ -13,7 +13,8 @@ verify.moveToNewFile({
|
||||
"/a.ts": "",
|
||||
|
||||
"/x.ts":
|
||||
`export const [x, { p: y }] = [0, { p: 1 }];`,
|
||||
`export const [x, { p: y }] = [0, { p: 1 }];
|
||||
`,
|
||||
|
||||
"/b.ts":
|
||||
`
|
||||
|
||||
@@ -33,6 +33,7 @@ export namespace N {
|
||||
}
|
||||
export type T = number;
|
||||
export interface I {
|
||||
}`,
|
||||
}
|
||||
`,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -16,7 +16,8 @@ verify.moveToNewFile({
|
||||
f();`,
|
||||
|
||||
"/f.ts":
|
||||
`export default function f() { }`,
|
||||
`export default function f() { }
|
||||
`,
|
||||
|
||||
"/user.ts":
|
||||
`import f from "./f";
|
||||
|
||||
@@ -12,6 +12,7 @@ verify.moveToNewFile({
|
||||
|
||||
"/x.ts":
|
||||
`import f from "./a";
|
||||
const x = f();`,
|
||||
const x = f();
|
||||
`,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -15,6 +15,7 @@ M;`,
|
||||
|
||||
"/O.ts":
|
||||
`import { N } from "./a";
|
||||
export import O = N;`,
|
||||
export import O = N;
|
||||
`,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -16,6 +16,7 @@ verify.moveToNewFile({
|
||||
"/f.ts":
|
||||
`function f() {
|
||||
const x = 0;
|
||||
}`,
|
||||
}
|
||||
`,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -23,7 +23,8 @@ verify.moveToNewFile({
|
||||
|
||||
"/g.ts":
|
||||
`import { C } from "./a";
|
||||
export const { g, h: i } = new C();`,
|
||||
export const { g, h: i } = new C();
|
||||
`,
|
||||
|
||||
"/b.ts":
|
||||
`
|
||||
|
||||
@@ -11,6 +11,7 @@ verify.moveToNewFile({
|
||||
`,
|
||||
|
||||
"/y.ts":
|
||||
`const y = x;`,
|
||||
`const y = x;
|
||||
`,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -13,6 +13,7 @@ verify.moveToNewFile({
|
||||
j;`,
|
||||
"/y.ts":
|
||||
`import i = require("./i");
|
||||
const y = i;`,
|
||||
const y = i;
|
||||
`,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -15,6 +15,7 @@ import { x } from './x';
|
||||
x;`,
|
||||
|
||||
"/x.ts":
|
||||
`export const x = 0;`,
|
||||
`export const x = 0;
|
||||
`,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -30,6 +30,7 @@ const { p } = require("./a");
|
||||
const y = p + b;
|
||||
exports.y = y;
|
||||
const z = 0;
|
||||
exports.z = 0;`,
|
||||
exports.z = 0;
|
||||
`,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -9,6 +9,7 @@ verify.moveToNewFile({
|
||||
``,
|
||||
|
||||
"/newFile.tsx":
|
||||
`<div>a</div>;`,
|
||||
`<div>a</div>;
|
||||
`,
|
||||
}
|
||||
});
|
||||
|
||||
@@ -14,6 +14,7 @@ b;`,
|
||||
"/l.ts":
|
||||
`import { a } from "m";
|
||||
let l;
|
||||
a;`,
|
||||
a;
|
||||
`,
|
||||
}
|
||||
});
|
||||
|
||||
@@ -23,6 +23,7 @@ x; y;`,
|
||||
export const x = 0;
|
||||
a;
|
||||
export const y = 1;
|
||||
b;`,
|
||||
b;
|
||||
`,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -27,7 +27,8 @@ verify.moveToNewFile({
|
||||
`export const y = 0;`,
|
||||
|
||||
"/x.ts":
|
||||
`export const x = 0;`,
|
||||
`export const x = 0;
|
||||
`,
|
||||
|
||||
"/b.ts":
|
||||
`import * as a from "./a";
|
||||
|
||||
@@ -15,6 +15,7 @@ verify.moveToNewFile({
|
||||
``,
|
||||
|
||||
"/x.2.ts":
|
||||
`export const x = 0;`,
|
||||
`export const x = 0;
|
||||
`,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -11,6 +11,7 @@ verify.moveToNewFile({
|
||||
`,
|
||||
|
||||
"/newFile.ts":
|
||||
`console.log("goodbye");`,
|
||||
`console.log("goodbye");
|
||||
`,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -13,6 +13,7 @@ verify.moveToNewFile({
|
||||
const y = 0;`,
|
||||
|
||||
"/x.ts":
|
||||
`const x = 0;`,
|
||||
`const x = 0;
|
||||
`,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -14,6 +14,7 @@ export {};
|
||||
export function gee() { eff(); }`,
|
||||
"/eff.ts":
|
||||
`import { gee } from "./a";
|
||||
export function eff() { gee(); }`,
|
||||
export function eff() { gee(); }
|
||||
`,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -18,7 +18,8 @@ verify.moveToNewFile({
|
||||
`,
|
||||
|
||||
"/src/newFile.ts":
|
||||
`1;`,
|
||||
`1;
|
||||
`,
|
||||
|
||||
"/src/tsconfig.json":
|
||||
`{
|
||||
|
||||
@@ -17,7 +17,8 @@ verify.moveToNewFile({
|
||||
`,
|
||||
|
||||
"/y.ts":
|
||||
`export const y = 0;`,
|
||||
`export const y = 0;
|
||||
`,
|
||||
|
||||
"/user.ts":
|
||||
`import { x } from "./a";
|
||||
|
||||
@@ -19,7 +19,8 @@ verify.moveToNewFile({
|
||||
`,
|
||||
|
||||
"/y.js":
|
||||
`exports.y = 0;`,
|
||||
`exports.y = 0;
|
||||
`,
|
||||
|
||||
"/user.js":
|
||||
// TODO: GH#22330
|
||||
|
||||
@@ -14,6 +14,7 @@ export let x;
|
||||
|
||||
"/y.ts":
|
||||
`import { x } from "./a";
|
||||
const y = x;`,
|
||||
const y = x;
|
||||
`,
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user