Skip to content
Open
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
4 changes: 4 additions & 0 deletions tsc/internal/execute/incremental/programtosnapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ func (t *toProgramSnapshot) handlePendingCheck() {

func fileAffectsGlobalScope(file *ast.SourceFile) bool {
binder.BindSourceFile(file)
// UMD exports introduce global names even though the file is an external module.
if len(file.GlobalExports) > 0 {
return true
}
// if file contains anything that augments to global scope we need to build them as if
// they are global files as well as module
if core.Some(file.ModuleAugmentations, func(augmentation *ast.ModuleName) bool {
Expand Down
72 changes: 72 additions & 0 deletions tsc/internal/execute/tsctests/umd_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package tsctests

import "testing"

func TestTscUMD(t *testing.T) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should just be in an existing tsc test. We have places for these that are not new files.

t.Parallel()
for _, args := range [][]string{nil, {"--watch"}} {
const umdPath = "/home/src/workspaces/project/umd.d.ts"
const present = "export as namespace UmdApi;\nexport interface Item { value: number }\n"
(&tscInput{
subScenario: "UMD global export changes invalidate unchanged consumers",
commandLineArgs: args,
files: FileMap{
"/home/src/workspaces/project/tsconfig.json": `{"compilerOptions":{"strict":true,"incremental":true,"noEmit":true,"types":[]},"include":["*.ts"]}`,
umdPath: present,
"/home/src/workspaces/project/client.ts": "declare const item: UmdApi.Item;\nconst checked: number = item.value;\n",
},
edits: []*tscEdit{
noChange,
{
caption: "remove the global namespace export",
edit: func(sys *TestSys) {
sys.writeFileNoError(umdPath, "export interface Item { value: number }\n")
},
},
{
caption: "restore the global namespace export",
edit: func(sys *TestSys) {
sys.writeFileNoError(umdPath, present)
},
},
{
caption: "rename the global namespace export",
edit: func(sys *TestSys) {
sys.replaceFileText(umdPath, "UmdApi", "OtherApi")
},
},
{
caption: "restore the global namespace name",
edit: func(sys *TestSys) {
sys.writeFileNoError(umdPath, present)
},
},
{
caption: "make the exported property incompatible",
edit: func(sys *TestSys) {
sys.replaceFileText(umdPath, "value: number", "value: string")
},
},
{
caption: "restore the exported property type",
edit: func(sys *TestSys) {
sys.writeFileNoError(umdPath, present)
},
},
{
caption: "delete the UMD declaration file",
edit: func(sys *TestSys) {
sys.removeNoError(umdPath)
},
},
{
caption: "restore the UMD declaration file",
edit: func(sys *TestSys) {
sys.writeFileNoError(umdPath, present)
},
},
noChange,
},
}).run(t, "umd")
}
}