Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/core/compileroptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type CompilerOptions struct {
ForceConsistentCasingInFileNames Tristate `json:"forceConsistentCasingInFileNames,omitzero"`
IsolatedModules Tristate `json:"isolatedModules,omitzero"`
IsolatedDeclarations Tristate `json:"isolatedDeclarations,omitzero"`
IgnoreConfig Tristate `json:"ignoreConfig,omitzero"`
IgnoreDeprecations string `json:"ignoreDeprecations,omitzero"`
ImportHelpers Tristate `json:"importHelpers,omitzero"`
InlineSourceMap Tristate `json:"inlineSourceMap,omitzero"`
Expand Down
8 changes: 8 additions & 0 deletions pkg/diagnostics/diagnostics_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions pkg/diagnostics/extraDiagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,13 @@
"Locale must be an IETF BCP 47 language tag. Examples: '{0}', '{1}'.": {
"category": "Error",
"code": 6048
},
"Ignore the tsconfig found and build with commandline options and files.": {
"category": "Message",
"code": 1549
},
"tsconfig.json is present but will not be loaded if files are specified on commandline. Use '--ignoreConfig' to skip this error.": {
"category": "Error",
"code": 5112
}
}
25 changes: 15 additions & 10 deletions pkg/execute/tsc.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,19 +150,24 @@ func tscCompilation(sys tsc.System, commandLine *tsoptions.ParsedCommandLine, te
return tsc.CommandLineResult{Status: tsc.ExitStatusDiagnosticsPresent_OutputsSkipped}
}
}
} else if len(commandLine.FileNames()) == 0 {
} else if !commandLine.CompilerOptions().IgnoreConfig.IsTrue() || len(commandLine.FileNames()) == 0 {
searchPath := tspath.NormalizePath(sys.GetCurrentDirectory())
configFileName = findConfigFile(searchPath, sys.FS().FileExists, "tsconfig.json")
}

if configFileName == "" && len(commandLine.FileNames()) == 0 {
if commandLine.CompilerOptions().ShowConfig.IsTrue() {
reportDiagnostic(ast.NewCompilerDiagnostic(diagnostics.Cannot_find_a_tsconfig_json_file_at_the_current_directory_Colon_0, tspath.NormalizePath(sys.GetCurrentDirectory())))
} else {
tsc.PrintVersion(sys, locale)
tsc.PrintHelp(sys, locale, commandLine)
if len(commandLine.FileNames()) != 0 {
if configFileName != "" {
// Error to not specify config file
reportDiagnostic(ast.NewCompilerDiagnostic(diagnostics.X_tsconfig_json_is_present_but_will_not_be_loaded_if_files_are_specified_on_commandline_Use_ignoreConfig_to_skip_this_error))
return tsc.CommandLineResult{Status: tsc.ExitStatusDiagnosticsPresent_OutputsSkipped}
}
} else if configFileName == "" {
if commandLine.CompilerOptions().ShowConfig.IsTrue() {
reportDiagnostic(ast.NewCompilerDiagnostic(diagnostics.Cannot_find_a_tsconfig_json_file_at_the_current_directory_Colon_0, tspath.NormalizePath(sys.GetCurrentDirectory())))
} else {
tsc.PrintVersion(sys, locale)
tsc.PrintHelp(sys, locale, commandLine)
}
return tsc.CommandLineResult{Status: tsc.ExitStatusDiagnosticsPresent_OutputsSkipped}
}
return tsc.CommandLineResult{Status: tsc.ExitStatusDiagnosticsPresent_OutputsSkipped}
}

// !!! convert to options with absolute paths is usually done here, but for ease of implementation, it's done in `tsoptions.ParseCommandLine()`
Expand Down
53 changes: 53 additions & 0 deletions pkg/execute/tsctests/tsc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,59 @@ func TestTscExtends(t *testing.T) {
}
}

func TestTscIgnoreConfig(t *testing.T) {
t.Parallel()
filesWithoutConfig := func() FileMap {
return FileMap{
"/home/src/workspaces/project/src/a.ts": "export const a = 10;",
"/home/src/workspaces/project/src/b.ts": "export const b = 10;",
"/home/src/workspaces/project/c.ts": "export const c = 10;",
}
}
filesWithConfig := func() FileMap {
files := filesWithoutConfig()
files["/home/src/workspaces/project/tsconfig.json"] = stringtestutil.Dedent(`
{
"include": ["src"],
}`)
return files
}
getScenarios := func(subScenario string, commandLineArgs []string) []*tscInput {
commandLineArgsIgnoreConfig := append(commandLineArgs, "--ignoreConfig")
return []*tscInput{
{
subScenario: subScenario,
files: filesWithConfig(),
commandLineArgs: commandLineArgs,
},
{
subScenario: subScenario + " with --ignoreConfig",
files: filesWithConfig(),
commandLineArgs: commandLineArgsIgnoreConfig,
},
{
subScenario: subScenario + " when config file absent",
files: filesWithoutConfig(),
commandLineArgs: commandLineArgs,
},
{
subScenario: subScenario + " when config file absent with --ignoreConfig",
files: filesWithoutConfig(),
commandLineArgs: commandLineArgsIgnoreConfig,
},
}
}
testCases := slices.Concat(
getScenarios("without any options", nil),
getScenarios("specifying files", []string{"src/a.ts"}),
getScenarios("specifying project", []string{"-p", "."}),
getScenarios("mixing project and files", []string{"-p", ".", "src/a.ts", "c.ts"}),
)
for _, test := range testCases {
test.run(t, "ignoreConfig")
}
}

func TestTscIncremental(t *testing.T) {
t.Parallel()
getConstEnumTest := func(bdsContents string, changeEnumFile string, testSuffix string) *tscInput {
Expand Down
1 change: 0 additions & 1 deletion pkg/fourslash/_scripts/failingTests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ TestGetJavaScriptCompletions10
TestGetJavaScriptCompletions12
TestGetJavaScriptCompletions13
TestGetJavaScriptCompletions15
TestGetJavaScriptCompletions18
TestGetJavaScriptCompletions20
TestGetJavaScriptCompletions8
TestGetJavaScriptCompletions9
Expand Down
2 changes: 1 addition & 1 deletion pkg/fourslash/tests/gen/getJavaScriptCompletions18_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func TestGetJavaScriptCompletions18(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `// @allowNonTsExtensions: true
// @Filename: file.js
Expand Down
4 changes: 4 additions & 0 deletions pkg/parser/reparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,10 @@ func getFunctionLikeHost(host *ast.Node) (*ast.Node, bool) {
fun = host.Expression()
} else if host.Kind == ast.KindReturnStatement {
fun = host.Expression()
} else if host.Kind == ast.KindExpressionStatement {
if ast.IsBinaryExpression(host.Expression()) {
fun = host.Expression().AsBinaryExpression().Right
}
}
if ast.IsFunctionLike(fun) {
return fun, true
Expand Down
9 changes: 9 additions & 0 deletions pkg/tsoptions/declscompiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,15 @@ var optionsForCompiler = []*CommandLineOption{
Description: diagnostics.Print_names_of_files_that_are_part_of_the_compilation_and_then_stop_processing,
DefaultValueDescription: false,
},
{
Name: "ignoreConfig",
Kind: CommandLineOptionTypeBoolean,
ShowInSimplifiedHelpView: true,
Category: diagnostics.Command_line_Options,
IsCommandLineOnly: true,
Description: diagnostics.Ignore_the_tsconfig_found_and_build_with_commandline_options_and_files,
DefaultValueDescription: false,
},

// Basic
// targetOptionDeclaration,
Expand Down
2 changes: 2 additions & 0 deletions pkg/tsoptions/parsinghelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ func parseCompilerOptions(key string, value any, allOptions *core.CompilerOption
allOptions.GenerateTrace = ParseString(value)
case "isolatedModules":
allOptions.IsolatedModules = ParseTristate(value)
case "ignoreConfig":
allOptions.IgnoreConfig = ParseTristate(value)
case "ignoreDeprecations":
allOptions.IgnoreDeprecations = ParseString(value)
case "importHelpers":
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,26 @@ module.exports = function loader(options) { };
export type Options = {
opt: string;
};
declare const _default: (options: any) => void;
declare const _default: (options: Options) => void;
export = _default;


//// [DtsFileErrors]


out/index.d.ts(9,1): error TS2309: An export assignment cannot be used in a module with other exported elements.


==== out/index.d.ts (1 errors) ====
/**
* @typedef Options
* @property {string} opt
*/
export type Options = {
opt: string;
};
declare const _default: (options: Options) => void;
export = _default;
~~~~~~~~~~~~~~~~~~
!!! error TS2309: An export assignment cannot be used in a module with other exported elements.

Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,26 @@
+export type Options = {
opt: string;
};
+declare const _default: (options: any) => void;
+export = _default;
+declare const _default: (options: Options) => void;
+export = _default;
+
+
+//// [DtsFileErrors]
+
+
+out/index.d.ts(9,1): error TS2309: An export assignment cannot be used in a module with other exported elements.
+
+
+==== out/index.d.ts (1 errors) ====
+ /**
+ * @typedef Options
+ * @property {string} opt
+ */
+ export type Options = {
+ opt: string;
+ };
+ declare const _default: (options: Options) => void;
+ export = _default;
+ ~~~~~~~~~~~~~~~~~~
+!!! error TS2309: An export assignment cannot be used in a module with other exported elements.
+
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
* @param {Options} options
*/
module.exports = function loader(options) {}
>module.exports = function loader(options) {} : (options: any) => void
>module.exports : (options: any) => void
>module : { "export=": (options: any) => void; }
>exports : (options: any) => void
>function loader(options) {} : (options: any) => void
>loader : (options: any) => void
>options : any
>module.exports = function loader(options) {} : (options: Options) => void
>module.exports : (options: Options) => void
>module : { "export=": (options: Options) => void; }
>exports : (options: Options) => void
>function loader(options) {} : (options: Options) => void
>loader : (options: Options) => void
>options : Options

Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
--- old.jsDeclarationEmitExportAssignedFunctionWithExtraTypedefsMembers.types
+++ new.jsDeclarationEmitExportAssignedFunctionWithExtraTypedefsMembers.types
@@= skipped -9, +9 lines =@@
* @param {Options} options
*/
@@= skipped -11, +11 lines =@@
module.exports = function loader(options) {}
->module.exports = function loader(options) {} : (options: Options) => void
->module.exports : (options: Options) => void
>module.exports = function loader(options) {} : (options: Options) => void
>module.exports : (options: Options) => void
->module : { exports: (options: Options) => void; }
->exports : (options: Options) => void
->function loader(options) {} : (options: Options) => void
->loader : (options: Options) => void
->options : Options
+>module.exports = function loader(options) {} : (options: any) => void
+>module.exports : (options: any) => void
+>module : { "export=": (options: any) => void; }
+>exports : (options: any) => void
+>function loader(options) {} : (options: any) => void
+>loader : (options: any) => void
+>options : any
+>module : { "export=": (options: Options) => void; }
>exports : (options: Options) => void
>function loader(options) {} : (options: Options) => void
>loader : (options: Options) => void
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
jsElementAccessNoContextualTypeCrash.js(2,1): error TS2322: Type '{ localize: (string: any) => any; } | {}' is not assignable to type '{ localize: (string: any) => any; }'.
Property 'localize' is missing in type '{}' but required in type '{ localize: (string: any) => any; }'.
jsElementAccessNoContextualTypeCrash.js(2,1): error TS2322: Type '{ localize: (string: string) => string; } | {}' is not assignable to type '{ localize: (string: string) => string; }'.
Property 'localize' is missing in type '{}' but required in type '{ localize: (string: string) => string; }'.


==== jsElementAccessNoContextualTypeCrash.js (1 errors) ====
var Common = {};
self['Common'] = self['Common'] || {};
~~~~~~~~~~~~~~
!!! error TS2322: Type '{ localize: (string: any) => any; } | {}' is not assignable to type '{ localize: (string: any) => any; }'.
!!! error TS2322: Property 'localize' is missing in type '{}' but required in type '{ localize: (string: any) => any; }'.
!!! error TS2322: Type '{ localize: (string: string) => string; } | {}' is not assignable to type '{ localize: (string: string) => string; }'.
!!! error TS2322: Property 'localize' is missing in type '{}' but required in type '{ localize: (string: string) => string; }'.
!!! related TS2728 jsElementAccessNoContextualTypeCrash.js:7:1: 'localize' is declared here.
/**
* @param {string} string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
+++ new.jsElementAccessNoContextualTypeCrash.errors.txt
@@= skipped -0, +0 lines =@@
-jsElementAccessNoContextualTypeCrash.js(2,1): error TS2741: Property 'localize' is missing in type '{}' but required in type 'typeof Common'.
+jsElementAccessNoContextualTypeCrash.js(2,1): error TS2322: Type '{ localize: (string: any) => any; } | {}' is not assignable to type '{ localize: (string: any) => any; }'.
+ Property 'localize' is missing in type '{}' but required in type '{ localize: (string: any) => any; }'.
+jsElementAccessNoContextualTypeCrash.js(2,1): error TS2322: Type '{ localize: (string: string) => string; } | {}' is not assignable to type '{ localize: (string: string) => string; }'.
+ Property 'localize' is missing in type '{}' but required in type '{ localize: (string: string) => string; }'.


==== jsElementAccessNoContextualTypeCrash.js (1 errors) ====
var Common = {};
self['Common'] = self['Common'] || {};
~~~~~~~~~~~~~~
-!!! error TS2741: Property 'localize' is missing in type '{}' but required in type 'typeof Common'.
+!!! error TS2322: Type '{ localize: (string: any) => any; } | {}' is not assignable to type '{ localize: (string: any) => any; }'.
+!!! error TS2322: Property 'localize' is missing in type '{}' but required in type '{ localize: (string: any) => any; }'.
+!!! error TS2322: Type '{ localize: (string: string) => string; } | {}' is not assignable to type '{ localize: (string: string) => string; }'.
+!!! error TS2322: Property 'localize' is missing in type '{}' but required in type '{ localize: (string: string) => string; }'.
!!! related TS2728 jsElementAccessNoContextualTypeCrash.js:7:1: 'localize' is declared here.
/**
* @param {string} string
Loading