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
2 changes: 1 addition & 1 deletion pkg/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -13987,7 +13987,7 @@ func (c *Checker) checkAndReportErrorForResolvingImportAliasToTypeOnlySymbol(nod
// TODO: how to get name for export *?
name := "*"
if !ast.IsExportDeclaration(typeOnlyDeclaration) {
name = getNameFromImportDeclaration(typeOnlyDeclaration).Text()
name = typeOnlyDeclaration.Name().Text()
}
c.error(decl.ModuleReference, message).AddRelatedInfo(createDiagnosticForNode(typeOnlyDeclaration, relatedMessage, name))
}
Expand Down
14 changes: 0 additions & 14 deletions pkg/checker/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,20 +189,6 @@ func IsInTypeQuery(node *ast.Node) bool {
}) != nil
}

func getNameFromImportDeclaration(node *ast.Node) *ast.Node {
switch node.Kind {
case ast.KindImportSpecifier:
return node.AsImportSpecifier().Name()
case ast.KindNamespaceImport:
return node.AsNamespaceImport().Name()
case ast.KindImportClause:
return node.AsImportClause().Name()
case ast.KindImportEqualsDeclaration:
return node.AsImportEqualsDeclaration().Name()
}
return nil
}

func nodeCanBeDecorated(useLegacyDecorators bool, node *ast.Node, parent *ast.Node, grandparent *ast.Node) bool {
// private names cannot be used with decorators yet
if useLegacyDecorators && node.Name() != nil && ast.IsPrivateIdentifier(node.Name()) {
Expand Down
9 changes: 8 additions & 1 deletion pkg/execute/tsc.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,14 @@ func tscCompilation(sys tsc.System, commandLine *tsoptions.ParsedCommandLine, te
return tsc.CommandLineResult{Status: tsc.ExitStatusSuccess}
}
if configForCompilation.CompilerOptions().Watch.IsTrue() {
watcher := createWatcher(sys, configForCompilation, reportDiagnostic, reportErrorSummary, testing)
watcher := createWatcher(
sys,
configForCompilation,
compilerOptionsFromCommandLine,
reportDiagnostic,
reportErrorSummary,
testing,
)
watcher.start()
return tsc.CommandLineResult{Status: tsc.ExitStatusSuccess, Watcher: watcher}
} else if configForCompilation.CompilerOptions().IsIncremental() {
Expand Down
35 changes: 22 additions & 13 deletions pkg/execute/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ import (
)

type Watcher struct {
sys tsc.System
configFileName string
config *tsoptions.ParsedCommandLine
reportDiagnostic tsc.DiagnosticReporter
reportErrorSummary tsc.DiagnosticsReporter
testing tsc.CommandLineTesting
sys tsc.System
configFileName string
config *tsoptions.ParsedCommandLine
compilerOptionsFromCommandLine *core.CompilerOptions
reportDiagnostic tsc.DiagnosticReporter
reportErrorSummary tsc.DiagnosticsReporter
testing tsc.CommandLineTesting

host compiler.CompilerHost
program *incremental.Program
Expand All @@ -29,13 +30,21 @@ type Watcher struct {

var _ tsc.Watcher = (*Watcher)(nil)

func createWatcher(sys tsc.System, configParseResult *tsoptions.ParsedCommandLine, reportDiagnostic tsc.DiagnosticReporter, reportErrorSummary tsc.DiagnosticsReporter, testing tsc.CommandLineTesting) *Watcher {
func createWatcher(
sys tsc.System,
configParseResult *tsoptions.ParsedCommandLine,
compilerOptionsFromCommandLine *core.CompilerOptions,
reportDiagnostic tsc.DiagnosticReporter,
reportErrorSummary tsc.DiagnosticsReporter,
testing tsc.CommandLineTesting,
) *Watcher {
w := &Watcher{
sys: sys,
config: configParseResult,
reportDiagnostic: reportDiagnostic,
reportErrorSummary: reportErrorSummary,
testing: testing,
sys: sys,
config: configParseResult,
compilerOptionsFromCommandLine: compilerOptionsFromCommandLine,
reportDiagnostic: reportDiagnostic,
reportErrorSummary: reportErrorSummary,
testing: testing,
// reportWatchStatus: createWatchStatusReporter(sys, configParseResult.CompilerOptions().Pretty),
}
if configParseResult.ConfigFile != nil {
Expand Down Expand Up @@ -108,7 +117,7 @@ func (w *Watcher) hasErrorsInTsConfig() bool {
extendedConfigCache := &tsc.ExtendedConfigCache{}
if w.configFileName != "" {
// !!! need to check that this merges compileroptions correctly. This differs from non-watch, since we allow overriding of previous options
configParseResult, errors := tsoptions.GetParsedCommandLineOfConfigFile(w.configFileName, &core.CompilerOptions{}, w.sys, extendedConfigCache)
configParseResult, errors := tsoptions.GetParsedCommandLineOfConfigFile(w.configFileName, w.compilerOptionsFromCommandLine, w.sys, extendedConfigCache)
if len(errors) > 0 {
for _, e := range errors {
w.reportDiagnostic(e)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
t.ts(2,14): error TS1379: An import alias cannot reference a declaration that was exported using 'export type'.


==== t.ts (1 errors) ====
import a = require("./a");
import foo = a.Foo
~~~~~
!!! error TS1379: An import alias cannot reference a declaration that was exported using 'export type'.
!!! related TS1377 a.ts:2:15: 'Foo' was exported here.

==== a.ts (0 errors) ====
type Foo = { x: number }
export type { Foo };

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//// [tests/cases/compiler/importAliasTypeOnlyExport.ts] ////

=== t.ts ===
import a = require("./a");
>a : Symbol(a, Decl(t.ts, 0, 0))

import foo = a.Foo
>foo : Symbol(foo, Decl(t.ts, 0, 26))
>a : Symbol(a, Decl(t.ts, 0, 0))
>Foo : Symbol(a.Foo, Decl(a.ts, 1, 13))

=== a.ts ===
type Foo = { x: number }
>Foo : Symbol(Foo, Decl(a.ts, 0, 0))
>x : Symbol(x, Decl(a.ts, 0, 12))

export type { Foo };
>Foo : Symbol(Foo, Decl(a.ts, 1, 13))

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//// [tests/cases/compiler/importAliasTypeOnlyExport.ts] ////

=== t.ts ===
import a = require("./a");
>a : typeof a

import foo = a.Foo
>foo : any
>a : typeof a
>Foo : foo

=== a.ts ===
type Foo = { x: number }
>Foo : Foo
>x : number

export type { Foo };
>Foo : Foo

Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,45 @@ interface Symbol {
declare const console: { log(msg: any): void; };
//// [/home/src/workspaces/project/index.js] *new*

//// [/home/src/workspaces/project/tsconfig.tsbuildinfo] *new*
{"version":"FakeTSVersion","root":[2],"fileNames":["lib.d.ts","./index.ts"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedNodeFormat":1},"99aa06d3014798d86001c324468d497f-"]}
//// [/home/src/workspaces/project/tsconfig.tsbuildinfo.readable.baseline.txt] *new*
{
"version": "FakeTSVersion",
"root": [
{
"files": [
"./index.ts"
],
"original": 2
}
],
"fileNames": [
"lib.d.ts",
"./index.ts"
],
"fileInfos": [
{
"fileName": "lib.d.ts",
"version": "8859c12c614ce56ba9a18e58384a198f-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };",
"signature": "8859c12c614ce56ba9a18e58384a198f-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };",
"affectsGlobalScope": true,
"impliedNodeFormat": "CommonJS",
"original": {
"version": "8859c12c614ce56ba9a18e58384a198f-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };",
"affectsGlobalScope": true,
"impliedNodeFormat": 1
}
},
{
"fileName": "./index.ts",
"version": "99aa06d3014798d86001c324468d497f-",
"signature": "99aa06d3014798d86001c324468d497f-",
"impliedNodeFormat": "CommonJS"
}
],
"size": 896
}

tsconfig.json::
SemanticDiagnostics::
Expand Down
11 changes: 11 additions & 0 deletions testdata/tests/cases/compiler/importAliasTypeOnlyExport.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// @target: esnext
// @module: commonjs
// @noEmit: true

// @filename: t.ts
import a = require("./a");
import foo = a.Foo

// @filename: a.ts
type Foo = { x: number }
export type { Foo };