@@ -25,6 +25,7 @@ import (
25
25
"github.com/microsoft/typescript-go/internal/printer"
26
26
"github.com/microsoft/typescript-go/internal/scanner"
27
27
"github.com/microsoft/typescript-go/internal/stringutil"
28
+ "github.com/microsoft/typescript-go/internal/tsoptions"
28
29
"github.com/microsoft/typescript-go/internal/tspath"
29
30
)
30
31
@@ -527,6 +528,7 @@ type Program interface {
527
528
BindSourceFiles()
528
529
FileExists(fileName string) bool
529
530
GetSourceFile(fileName string) *ast.SourceFile
531
+ GetSourceFileForResolvedModule(fileName string) *ast.SourceFile
530
532
GetEmitModuleFormatOfFile(sourceFile ast.HasFileName) core.ModuleKind
531
533
GetEmitSyntaxForUsageLocation(sourceFile ast.HasFileName, usageLocation *ast.StringLiteralLike) core.ResolutionMode
532
534
GetImpliedNodeFormatForEmit(sourceFile ast.HasFileName) core.ModuleKind
@@ -535,6 +537,8 @@ type Program interface {
535
537
GetSourceFileMetaData(path tspath.Path) *ast.SourceFileMetaData
536
538
GetJSXRuntimeImportSpecifier(path tspath.Path) (moduleReference string, specifier *ast.Node)
537
539
GetImportHelpersImportSpecifier(path tspath.Path) *ast.Node
540
+ IsSourceFromProjectReference(path tspath.Path) bool
541
+ GetSourceAndProjectReference(path tspath.Path) *tsoptions.SourceAndProjectReference
538
542
}
539
543
540
544
type Host interface {
@@ -2086,7 +2090,7 @@ func (c *Checker) getSymbol(symbols ast.SymbolTable, name string, meaning ast.Sy
2086
2090
}
2087
2091
2088
2092
func (c *Checker) CheckSourceFile(ctx context.Context, sourceFile *ast.SourceFile) {
2089
- if SkipTypeChecking(sourceFile, c.compilerOptions) {
2093
+ if SkipTypeChecking(sourceFile, c.compilerOptions, c.program ) {
2090
2094
return
2091
2095
}
2092
2096
c.checkSourceFile(ctx, sourceFile)
@@ -6462,15 +6466,13 @@ func (c *Checker) checkAliasSymbol(node *ast.Node) {
6462
6466
// in files that are unambiguously CommonJS in this mode.
6463
6467
c.error(node, diagnostics.ESM_syntax_is_not_allowed_in_a_CommonJS_module_when_module_is_set_to_preserve)
6464
6468
}
6465
- // !!!
6466
-
6467
- // if c.compilerOptions.VerbatimModuleSyntax.IsTrue() && !ast.IsTypeOnlyImportOrExportDeclaration(node) && node.Flags&ast.NodeFlagsAmbient == 0 && targetFlags&ast.SymbolFlagsConstEnum != 0 {
6468
- // constEnumDeclaration := target.ValueDeclaration
6469
- // redirect := host.getRedirectReferenceForResolutionFromSourceOfProject(ast.GetSourceFileOfNode(constEnumDeclaration).ResolvedPath)
6470
- // if constEnumDeclaration.Flags&ast.NodeFlagsAmbient != 0 && (redirect == nil || !shouldPreserveConstEnums(redirect.commandLine.options)) {
6471
- // c.error(node, diagnostics.Cannot_access_ambient_const_enums_when_0_is_enabled, c.getIsolatedModulesLikeFlagName())
6472
- // }
6473
- // }
6469
+ if c.compilerOptions.VerbatimModuleSyntax.IsTrue() && !ast.IsTypeOnlyImportOrExportDeclaration(node) && node.Flags&ast.NodeFlagsAmbient == 0 && targetFlags&ast.SymbolFlagsConstEnum != 0 {
6470
+ constEnumDeclaration := target.ValueDeclaration
6471
+ redirect := c.program.GetSourceAndProjectReference(ast.GetSourceFileOfNode(constEnumDeclaration).Path())
6472
+ if constEnumDeclaration.Flags&ast.NodeFlagsAmbient != 0 && (redirect == nil || !redirect.Resolved.CompilerOptions().ShouldPreserveConstEnums()) {
6473
+ c.error(node, diagnostics.Cannot_access_ambient_const_enums_when_0_is_enabled, c.getIsolatedModulesLikeFlagName())
6474
+ }
6475
+ }
6474
6476
}
6475
6477
if ast.IsImportSpecifier(node) {
6476
6478
targetSymbol := c.resolveAliasWithDeprecationCheck(symbol, node)
@@ -7184,15 +7186,14 @@ func (c *Checker) checkConstEnumAccess(node *ast.Node, t *Type) {
7184
7186
// --verbatimModuleSyntax only gets checked here when the enum usage does not
7185
7187
// resolve to an import, because imports of ambient const enums get checked
7186
7188
// separately in `checkAliasSymbol`.
7187
- // !!!
7188
- // if c.compilerOptions.IsolatedModules.IsTrue() || c.compilerOptions.VerbatimModuleSyntax.IsTrue() && ok && c.resolveName(node, getFirstIdentifier(node).Text(), ast.SymbolFlagsAlias, nil, false, true) == nil {
7189
- // // Debug.assert(t.symbol.Flags&ast.SymbolFlagsConstEnum != 0)
7190
- // constEnumDeclaration := t.symbol.ValueDeclaration
7191
- // redirect := host.getRedirectReferenceForResolutionFromSourceOfProject(ast.GetSourceFileOfNode(constEnumDeclaration).ResolvedPath)
7192
- // if constEnumDeclaration.Flags&ast.NodeFlagsAmbient != 0 && !isValidTypeOnlyAliasUseSite(node) && (redirect == nil || !shouldPreserveConstEnums(redirect.commandLine.options)) {
7193
- // c.error(node, diagnostics.Cannot_access_ambient_const_enums_when_0_is_enabled, c.getIsolatedModulesLikeFlagName())
7194
- // }
7195
- // }
7189
+ if c.compilerOptions.IsolatedModules.IsTrue() || c.compilerOptions.VerbatimModuleSyntax.IsTrue() && ok && c.resolveName(node, ast.GetFirstIdentifier(node).Text(), ast.SymbolFlagsAlias, nil, false, true) == nil {
7190
+ // Debug.assert(t.symbol.Flags&ast.SymbolFlagsConstEnum != 0)
7191
+ constEnumDeclaration := t.symbol.ValueDeclaration
7192
+ redirect := c.program.GetSourceAndProjectReference(ast.GetSourceFileOfNode(constEnumDeclaration).Path())
7193
+ if constEnumDeclaration.Flags&ast.NodeFlagsAmbient != 0 && !ast.IsValidTypeOnlyAliasUseSite(node) && (redirect == nil || !redirect.Resolved.CompilerOptions().ShouldPreserveConstEnums()) {
7194
+ c.error(node, diagnostics.Cannot_access_ambient_const_enums_when_0_is_enabled, c.getIsolatedModulesLikeFlagName())
7195
+ }
7196
+ }
7196
7197
}
7197
7198
7198
7199
func (c *Checker) instantiateTypeWithSingleGenericCallSignature(node *ast.Node, t *Type, checkMode CheckMode) *Type {
@@ -14467,7 +14468,7 @@ func (c *Checker) resolveExternalModule(location *ast.Node, moduleReference stri
14467
14468
var sourceFile *ast.SourceFile
14468
14469
resolvedModule := c.program.GetResolvedModule(importingSourceFile, moduleReference, mode)
14469
14470
if resolvedModule.IsResolved() {
14470
- sourceFile = c.program.GetSourceFile (resolvedModule.ResolvedFileName)
14471
+ sourceFile = c.program.GetSourceFileForResolvedModule (resolvedModule.ResolvedFileName)
14471
14472
}
14472
14473
14473
14474
if sourceFile != nil {
@@ -14573,6 +14574,21 @@ func (c *Checker) resolveExternalModule(location *ast.Node, moduleReference stri
14573
14574
}
14574
14575
14575
14576
if moduleNotFoundError != nil {
14577
+
14578
+ // See if this was possibly a projectReference redirect
14579
+ if resolvedModule.IsResolved() {
14580
+ redirect := c.program.GetOutputAndProjectReference(tspath.ToPath(resolvedModule.ResolvedFileName, c.program.GetCurrentDirectory(), c.program.UseCaseSensitiveFileNames()))
14581
+ if redirect != nil && redirect.OutputDts != "" {
14582
+ c.error(
14583
+ errorNode,
14584
+ diagnostics.Output_file_0_has_not_been_built_from_source_file_1,
14585
+ redirect.OutputDts,
14586
+ resolvedModule.ResolvedFileName,
14587
+ )
14588
+ return nil
14589
+ }
14590
+ }
14591
+
14576
14592
// !!!
14577
14593
isExtensionlessRelativePathImport := tspath.PathIsRelative(moduleReference) && !tspath.HasExtension(moduleReference)
14578
14594
resolutionIsNode16OrNext := c.moduleResolutionKind == core.ModuleResolutionKindNode16 || c.moduleResolutionKind == core.ModuleResolutionKindNodeNext
0 commit comments