@@ -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
@@ -526,6 +527,7 @@ type Program interface {
526
527
BindSourceFiles()
527
528
FileExists(fileName string) bool
528
529
GetSourceFile(fileName string) *ast.SourceFile
530
+ GetSourceFileForResolvedModule(fileName string) *ast.SourceFile
529
531
GetEmitModuleFormatOfFile(sourceFile ast.HasFileName) core.ModuleKind
530
532
GetEmitSyntaxForUsageLocation(sourceFile ast.HasFileName, usageLocation *ast.StringLiteralLike) core.ResolutionMode
531
533
GetImpliedNodeFormatForEmit(sourceFile ast.HasFileName) core.ModuleKind
@@ -534,6 +536,8 @@ type Program interface {
534
536
GetSourceFileMetaData(path tspath.Path) *ast.SourceFileMetaData
535
537
GetJSXRuntimeImportSpecifier(path tspath.Path) (moduleReference string, specifier *ast.Node)
536
538
GetImportHelpersImportSpecifier(path tspath.Path) *ast.Node
539
+ IsSourceFromProjectReference(path tspath.Path) bool
540
+ GetSourceAndProjectReference(path tspath.Path) *tsoptions.SourceAndProjectReference
537
541
}
538
542
539
543
type Host interface {
@@ -2081,7 +2085,7 @@ func (c *Checker) getSymbol(symbols ast.SymbolTable, name string, meaning ast.Sy
2081
2085
}
2082
2086
2083
2087
func (c *Checker) CheckSourceFile(ctx context.Context, sourceFile *ast.SourceFile) {
2084
- if SkipTypeChecking(sourceFile, c.compilerOptions) {
2088
+ if SkipTypeChecking(sourceFile, c.compilerOptions, c.program ) {
2085
2089
return
2086
2090
}
2087
2091
c.checkSourceFile(ctx, sourceFile)
@@ -6444,15 +6448,13 @@ func (c *Checker) checkAliasSymbol(node *ast.Node) {
6444
6448
// in files that are unambiguously CommonJS in this mode.
6445
6449
c.error(node, diagnostics.ESM_syntax_is_not_allowed_in_a_CommonJS_module_when_module_is_set_to_preserve)
6446
6450
}
6447
- // !!!
6448
-
6449
- // if c.compilerOptions.VerbatimModuleSyntax.IsTrue() && !ast.IsTypeOnlyImportOrExportDeclaration(node) && node.Flags&ast.NodeFlagsAmbient == 0 && targetFlags&ast.SymbolFlagsConstEnum != 0 {
6450
- // constEnumDeclaration := target.ValueDeclaration
6451
- // redirect := host.getRedirectReferenceForResolutionFromSourceOfProject(ast.GetSourceFileOfNode(constEnumDeclaration).ResolvedPath)
6452
- // if constEnumDeclaration.Flags&ast.NodeFlagsAmbient != 0 && (redirect == nil || !shouldPreserveConstEnums(redirect.commandLine.options)) {
6453
- // c.error(node, diagnostics.Cannot_access_ambient_const_enums_when_0_is_enabled, c.getIsolatedModulesLikeFlagName())
6454
- // }
6455
- // }
6451
+ if c.compilerOptions.VerbatimModuleSyntax.IsTrue() && !ast.IsTypeOnlyImportOrExportDeclaration(node) && node.Flags&ast.NodeFlagsAmbient == 0 && targetFlags&ast.SymbolFlagsConstEnum != 0 {
6452
+ constEnumDeclaration := target.ValueDeclaration
6453
+ redirect := c.program.GetSourceAndProjectReference(ast.GetSourceFileOfNode(constEnumDeclaration).Path())
6454
+ if constEnumDeclaration.Flags&ast.NodeFlagsAmbient != 0 && (redirect == nil || !redirect.Resolved.CompilerOptions().ShouldPreserveConstEnums()) {
6455
+ c.error(node, diagnostics.Cannot_access_ambient_const_enums_when_0_is_enabled, c.getIsolatedModulesLikeFlagName())
6456
+ }
6457
+ }
6456
6458
}
6457
6459
if ast.IsImportSpecifier(node) {
6458
6460
targetSymbol := c.resolveAliasWithDeprecationCheck(symbol, node)
@@ -7166,15 +7168,14 @@ func (c *Checker) checkConstEnumAccess(node *ast.Node, t *Type) {
7166
7168
// --verbatimModuleSyntax only gets checked here when the enum usage does not
7167
7169
// resolve to an import, because imports of ambient const enums get checked
7168
7170
// separately in `checkAliasSymbol`.
7169
- // !!!
7170
- // if c.compilerOptions.IsolatedModules.IsTrue() || c.compilerOptions.VerbatimModuleSyntax.IsTrue() && ok && c.resolveName(node, getFirstIdentifier(node).Text(), ast.SymbolFlagsAlias, nil, false, true) == nil {
7171
- // // Debug.assert(t.symbol.Flags&ast.SymbolFlagsConstEnum != 0)
7172
- // constEnumDeclaration := t.symbol.ValueDeclaration
7173
- // redirect := host.getRedirectReferenceForResolutionFromSourceOfProject(ast.GetSourceFileOfNode(constEnumDeclaration).ResolvedPath)
7174
- // if constEnumDeclaration.Flags&ast.NodeFlagsAmbient != 0 && !isValidTypeOnlyAliasUseSite(node) && (redirect == nil || !shouldPreserveConstEnums(redirect.commandLine.options)) {
7175
- // c.error(node, diagnostics.Cannot_access_ambient_const_enums_when_0_is_enabled, c.getIsolatedModulesLikeFlagName())
7176
- // }
7177
- // }
7171
+ if c.compilerOptions.IsolatedModules.IsTrue() || c.compilerOptions.VerbatimModuleSyntax.IsTrue() && ok && c.resolveName(node, ast.GetFirstIdentifier(node).Text(), ast.SymbolFlagsAlias, nil, false, true) == nil {
7172
+ // Debug.assert(t.symbol.Flags&ast.SymbolFlagsConstEnum != 0)
7173
+ constEnumDeclaration := t.symbol.ValueDeclaration
7174
+ redirect := c.program.GetSourceAndProjectReference(ast.GetSourceFileOfNode(constEnumDeclaration).Path())
7175
+ if constEnumDeclaration.Flags&ast.NodeFlagsAmbient != 0 && !ast.IsValidTypeOnlyAliasUseSite(node) && (redirect == nil || !redirect.Resolved.CompilerOptions().ShouldPreserveConstEnums()) {
7176
+ c.error(node, diagnostics.Cannot_access_ambient_const_enums_when_0_is_enabled, c.getIsolatedModulesLikeFlagName())
7177
+ }
7178
+ }
7178
7179
}
7179
7180
7180
7181
func (c *Checker) instantiateTypeWithSingleGenericCallSignature(node *ast.Node, t *Type, checkMode CheckMode) *Type {
@@ -14433,7 +14434,7 @@ func (c *Checker) resolveExternalModule(location *ast.Node, moduleReference stri
14433
14434
var sourceFile *ast.SourceFile
14434
14435
resolvedModule := c.program.GetResolvedModule(importingSourceFile, moduleReference, mode)
14435
14436
if resolvedModule.IsResolved() {
14436
- sourceFile = c.program.GetSourceFile (resolvedModule.ResolvedFileName)
14437
+ sourceFile = c.program.GetSourceFileForResolvedModule (resolvedModule.ResolvedFileName)
14437
14438
}
14438
14439
14439
14440
if sourceFile != nil {
@@ -14539,6 +14540,21 @@ func (c *Checker) resolveExternalModule(location *ast.Node, moduleReference stri
14539
14540
}
14540
14541
14541
14542
if moduleNotFoundError != nil {
14543
+
14544
+ // See if this was possibly a projectReference redirect
14545
+ if resolvedModule.IsResolved() {
14546
+ redirect := c.program.GetOutputAndProjectReference(tspath.ToPath(resolvedModule.ResolvedFileName, c.program.GetCurrentDirectory(), c.program.UseCaseSensitiveFileNames()))
14547
+ if redirect != nil && redirect.OutputDts != "" {
14548
+ c.error(
14549
+ errorNode,
14550
+ diagnostics.Output_file_0_has_not_been_built_from_source_file_1,
14551
+ redirect.OutputDts,
14552
+ resolvedModule.ResolvedFileName,
14553
+ )
14554
+ return nil
14555
+ }
14556
+ }
14557
+
14542
14558
// !!!
14543
14559
isExtensionlessRelativePathImport := tspath.PathIsRelative(moduleReference) && !tspath.HasExtension(moduleReference)
14544
14560
resolutionIsNode16OrNext := c.moduleResolutionKind == core.ModuleResolutionKindNode16 || c.moduleResolutionKind == core.ModuleResolutionKindNodeNext
0 commit comments