Skip to content

Commit 6cd61cf

Browse files
chore(sync): mirror internal packages into pkg/ (auto) (#31)
Co-authored-by: buke <1013738+buke@users.noreply.github.com>
1 parent 661479d commit 6cd61cf

File tree

122 files changed

+1735
-1160
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+1735
-1160
lines changed

pkg/core/compileroptions.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type CompilerOptions struct {
4747
ForceConsistentCasingInFileNames Tristate `json:"forceConsistentCasingInFileNames,omitzero"`
4848
IsolatedModules Tristate `json:"isolatedModules,omitzero"`
4949
IsolatedDeclarations Tristate `json:"isolatedDeclarations,omitzero"`
50+
IgnoreConfig Tristate `json:"ignoreConfig,omitzero"`
5051
IgnoreDeprecations string `json:"ignoreDeprecations,omitzero"`
5152
ImportHelpers Tristate `json:"importHelpers,omitzero"`
5253
InlineSourceMap Tristate `json:"inlineSourceMap,omitzero"`

pkg/diagnostics/diagnostics_generated.go

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/diagnostics/extraDiagnosticMessages.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,13 @@
4646
"Locale must be an IETF BCP 47 language tag. Examples: '{0}', '{1}'.": {
4747
"category": "Error",
4848
"code": 6048
49+
},
50+
"Ignore the tsconfig found and build with commandline options and files.": {
51+
"category": "Message",
52+
"code": 1549
53+
},
54+
"tsconfig.json is present but will not be loaded if files are specified on commandline. Use '--ignoreConfig' to skip this error.": {
55+
"category": "Error",
56+
"code": 5112
4957
}
5058
}

pkg/execute/tsc.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,19 +150,24 @@ func tscCompilation(sys tsc.System, commandLine *tsoptions.ParsedCommandLine, te
150150
return tsc.CommandLineResult{Status: tsc.ExitStatusDiagnosticsPresent_OutputsSkipped}
151151
}
152152
}
153-
} else if len(commandLine.FileNames()) == 0 {
153+
} else if !commandLine.CompilerOptions().IgnoreConfig.IsTrue() || len(commandLine.FileNames()) == 0 {
154154
searchPath := tspath.NormalizePath(sys.GetCurrentDirectory())
155155
configFileName = findConfigFile(searchPath, sys.FS().FileExists, "tsconfig.json")
156-
}
157-
158-
if configFileName == "" && len(commandLine.FileNames()) == 0 {
159-
if commandLine.CompilerOptions().ShowConfig.IsTrue() {
160-
reportDiagnostic(ast.NewCompilerDiagnostic(diagnostics.Cannot_find_a_tsconfig_json_file_at_the_current_directory_Colon_0, tspath.NormalizePath(sys.GetCurrentDirectory())))
161-
} else {
162-
tsc.PrintVersion(sys, locale)
163-
tsc.PrintHelp(sys, locale, commandLine)
156+
if len(commandLine.FileNames()) != 0 {
157+
if configFileName != "" {
158+
// Error to not specify config file
159+
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))
160+
return tsc.CommandLineResult{Status: tsc.ExitStatusDiagnosticsPresent_OutputsSkipped}
161+
}
162+
} else if configFileName == "" {
163+
if commandLine.CompilerOptions().ShowConfig.IsTrue() {
164+
reportDiagnostic(ast.NewCompilerDiagnostic(diagnostics.Cannot_find_a_tsconfig_json_file_at_the_current_directory_Colon_0, tspath.NormalizePath(sys.GetCurrentDirectory())))
165+
} else {
166+
tsc.PrintVersion(sys, locale)
167+
tsc.PrintHelp(sys, locale, commandLine)
168+
}
169+
return tsc.CommandLineResult{Status: tsc.ExitStatusDiagnosticsPresent_OutputsSkipped}
164170
}
165-
return tsc.CommandLineResult{Status: tsc.ExitStatusDiagnosticsPresent_OutputsSkipped}
166171
}
167172

168173
// !!! convert to options with absolute paths is usually done here, but for ease of implementation, it's done in `tsoptions.ParseCommandLine()`

pkg/execute/tsctests/tsc_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,59 @@ func TestTscExtends(t *testing.T) {
981981
}
982982
}
983983

984+
func TestTscIgnoreConfig(t *testing.T) {
985+
t.Parallel()
986+
filesWithoutConfig := func() FileMap {
987+
return FileMap{
988+
"/home/src/workspaces/project/src/a.ts": "export const a = 10;",
989+
"/home/src/workspaces/project/src/b.ts": "export const b = 10;",
990+
"/home/src/workspaces/project/c.ts": "export const c = 10;",
991+
}
992+
}
993+
filesWithConfig := func() FileMap {
994+
files := filesWithoutConfig()
995+
files["/home/src/workspaces/project/tsconfig.json"] = stringtestutil.Dedent(`
996+
{
997+
"include": ["src"],
998+
}`)
999+
return files
1000+
}
1001+
getScenarios := func(subScenario string, commandLineArgs []string) []*tscInput {
1002+
commandLineArgsIgnoreConfig := append(commandLineArgs, "--ignoreConfig")
1003+
return []*tscInput{
1004+
{
1005+
subScenario: subScenario,
1006+
files: filesWithConfig(),
1007+
commandLineArgs: commandLineArgs,
1008+
},
1009+
{
1010+
subScenario: subScenario + " with --ignoreConfig",
1011+
files: filesWithConfig(),
1012+
commandLineArgs: commandLineArgsIgnoreConfig,
1013+
},
1014+
{
1015+
subScenario: subScenario + " when config file absent",
1016+
files: filesWithoutConfig(),
1017+
commandLineArgs: commandLineArgs,
1018+
},
1019+
{
1020+
subScenario: subScenario + " when config file absent with --ignoreConfig",
1021+
files: filesWithoutConfig(),
1022+
commandLineArgs: commandLineArgsIgnoreConfig,
1023+
},
1024+
}
1025+
}
1026+
testCases := slices.Concat(
1027+
getScenarios("without any options", nil),
1028+
getScenarios("specifying files", []string{"src/a.ts"}),
1029+
getScenarios("specifying project", []string{"-p", "."}),
1030+
getScenarios("mixing project and files", []string{"-p", ".", "src/a.ts", "c.ts"}),
1031+
)
1032+
for _, test := range testCases {
1033+
test.run(t, "ignoreConfig")
1034+
}
1035+
}
1036+
9841037
func TestTscIncremental(t *testing.T) {
9851038
t.Parallel()
9861039
getConstEnumTest := func(bdsContents string, changeEnumFile string, testSuffix string) *tscInput {

pkg/fourslash/_scripts/failingTests.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ TestGetJavaScriptCompletions10
242242
TestGetJavaScriptCompletions12
243243
TestGetJavaScriptCompletions13
244244
TestGetJavaScriptCompletions15
245-
TestGetJavaScriptCompletions18
246245
TestGetJavaScriptCompletions20
247246
TestGetJavaScriptCompletions8
248247
TestGetJavaScriptCompletions9

pkg/fourslash/tests/gen/getJavaScriptCompletions18_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
func TestGetJavaScriptCompletions18(t *testing.T) {
1313
t.Parallel()
14-
t.Skip()
14+
1515
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
1616
const content = `// @allowNonTsExtensions: true
1717
// @Filename: file.js

pkg/parser/reparser.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,10 @@ func getFunctionLikeHost(host *ast.Node) (*ast.Node, bool) {
587587
fun = host.Expression()
588588
} else if host.Kind == ast.KindReturnStatement {
589589
fun = host.Expression()
590+
} else if host.Kind == ast.KindExpressionStatement {
591+
if ast.IsBinaryExpression(host.Expression()) {
592+
fun = host.Expression().AsBinaryExpression().Right
593+
}
590594
}
591595
if ast.IsFunctionLike(fun) {
592596
return fun, true

pkg/tsoptions/declscompiler.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,15 @@ var optionsForCompiler = []*CommandLineOption{
298298
Description: diagnostics.Print_names_of_files_that_are_part_of_the_compilation_and_then_stop_processing,
299299
DefaultValueDescription: false,
300300
},
301+
{
302+
Name: "ignoreConfig",
303+
Kind: CommandLineOptionTypeBoolean,
304+
ShowInSimplifiedHelpView: true,
305+
Category: diagnostics.Command_line_Options,
306+
IsCommandLineOnly: true,
307+
Description: diagnostics.Ignore_the_tsconfig_found_and_build_with_commandline_options_and_files,
308+
DefaultValueDescription: false,
309+
},
301310

302311
// Basic
303312
// targetOptionDeclaration,

pkg/tsoptions/parsinghelpers.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ func parseCompilerOptions(key string, value any, allOptions *core.CompilerOption
259259
allOptions.GenerateTrace = ParseString(value)
260260
case "isolatedModules":
261261
allOptions.IsolatedModules = ParseTristate(value)
262+
case "ignoreConfig":
263+
allOptions.IgnoreConfig = ParseTristate(value)
262264
case "ignoreDeprecations":
263265
allOptions.IgnoreDeprecations = ParseString(value)
264266
case "importHelpers":

0 commit comments

Comments
 (0)