@@ -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,7 @@ 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
+ GetSourceAndProjectReference(path tspath.Path) *tsoptions.SourceAndProjectReference
537
540
}
538
541
539
542
type Host interface {
@@ -2081,7 +2084,7 @@ func (c *Checker) getSymbol(symbols ast.SymbolTable, name string, meaning ast.Sy
2081
2084
}
2082
2085
2083
2086
func (c *Checker) CheckSourceFile(ctx context.Context, sourceFile *ast.SourceFile) {
2084
- if SkipTypeChecking(sourceFile, c.compilerOptions) {
2087
+ if SkipTypeChecking(sourceFile, c.compilerOptions, c.program.IsSourceFromProjectReference ) {
2085
2088
return
2086
2089
}
2087
2090
c.checkSourceFile(ctx, sourceFile)
@@ -6426,15 +6429,13 @@ func (c *Checker) checkAliasSymbol(node *ast.Node) {
6426
6429
// in files that are unambiguously CommonJS in this mode.
6427
6430
c.error(node, diagnostics.ESM_syntax_is_not_allowed_in_a_CommonJS_module_when_module_is_set_to_preserve)
6428
6431
}
6429
- // !!!
6430
-
6431
- // if c.compilerOptions.VerbatimModuleSyntax.IsTrue() && !ast.IsTypeOnlyImportOrExportDeclaration(node) && node.Flags&ast.NodeFlagsAmbient == 0 && targetFlags&ast.SymbolFlagsConstEnum != 0 {
6432
- // constEnumDeclaration := target.ValueDeclaration
6433
- // redirect := host.getRedirectReferenceForResolutionFromSourceOfProject(ast.GetSourceFileOfNode(constEnumDeclaration).ResolvedPath)
6434
- // if constEnumDeclaration.Flags&ast.NodeFlagsAmbient != 0 && (redirect == nil || !shouldPreserveConstEnums(redirect.commandLine.options)) {
6435
- // c.error(node, diagnostics.Cannot_access_ambient_const_enums_when_0_is_enabled, c.getIsolatedModulesLikeFlagName())
6436
- // }
6437
- // }
6432
+ if c.compilerOptions.VerbatimModuleSyntax.IsTrue() && !ast.IsTypeOnlyImportOrExportDeclaration(node) && node.Flags&ast.NodeFlagsAmbient == 0 && targetFlags&ast.SymbolFlagsConstEnum != 0 {
6433
+ constEnumDeclaration := target.ValueDeclaration
6434
+ redirect := c.program.GetSourceAndProjectReference(ast.GetSourceFileOfNode(constEnumDeclaration).Path())
6435
+ if constEnumDeclaration.Flags&ast.NodeFlagsAmbient != 0 && (redirect == nil || !redirect.Resolved.CompilerOptions().ShouldPreserveConstEnums()) {
6436
+ c.error(node, diagnostics.Cannot_access_ambient_const_enums_when_0_is_enabled, c.getIsolatedModulesLikeFlagName())
6437
+ }
6438
+ }
6438
6439
}
6439
6440
if ast.IsImportSpecifier(node) {
6440
6441
targetSymbol := c.resolveAliasWithDeprecationCheck(symbol, node)
@@ -7148,15 +7149,14 @@ func (c *Checker) checkConstEnumAccess(node *ast.Node, t *Type) {
7148
7149
// --verbatimModuleSyntax only gets checked here when the enum usage does not
7149
7150
// resolve to an import, because imports of ambient const enums get checked
7150
7151
// separately in `checkAliasSymbol`.
7151
- // !!!
7152
- // if c.compilerOptions.IsolatedModules.IsTrue() || c.compilerOptions.VerbatimModuleSyntax.IsTrue() && ok && c.resolveName(node, getFirstIdentifier(node).Text(), ast.SymbolFlagsAlias, nil, false, true) == nil {
7153
- // // Debug.assert(t.symbol.Flags&ast.SymbolFlagsConstEnum != 0)
7154
- // constEnumDeclaration := t.symbol.ValueDeclaration
7155
- // redirect := host.getRedirectReferenceForResolutionFromSourceOfProject(ast.GetSourceFileOfNode(constEnumDeclaration).ResolvedPath)
7156
- // if constEnumDeclaration.Flags&ast.NodeFlagsAmbient != 0 && !isValidTypeOnlyAliasUseSite(node) && (redirect == nil || !shouldPreserveConstEnums(redirect.commandLine.options)) {
7157
- // c.error(node, diagnostics.Cannot_access_ambient_const_enums_when_0_is_enabled, c.getIsolatedModulesLikeFlagName())
7158
- // }
7159
- // }
7152
+ if c.compilerOptions.IsolatedModules.IsTrue() || c.compilerOptions.VerbatimModuleSyntax.IsTrue() && ok && c.resolveName(node, ast.GetFirstIdentifier(node).Text(), ast.SymbolFlagsAlias, nil, false, true) == nil {
7153
+ // Debug.assert(t.symbol.Flags&ast.SymbolFlagsConstEnum != 0)
7154
+ constEnumDeclaration := t.symbol.ValueDeclaration
7155
+ redirect := c.program.GetSourceAndProjectReference(ast.GetSourceFileOfNode(constEnumDeclaration).Path())
7156
+ if constEnumDeclaration.Flags&ast.NodeFlagsAmbient != 0 && !ast.IsValidTypeOnlyAliasUseSite(node) && (redirect == nil || !redirect.Resolved.CompilerOptions().ShouldPreserveConstEnums()) {
7157
+ c.error(node, diagnostics.Cannot_access_ambient_const_enums_when_0_is_enabled, c.getIsolatedModulesLikeFlagName())
7158
+ }
7159
+ }
7160
7160
}
7161
7161
7162
7162
func (c *Checker) instantiateTypeWithSingleGenericCallSignature(node *ast.Node, t *Type, checkMode CheckMode) *Type {
@@ -14421,7 +14421,7 @@ func (c *Checker) resolveExternalModule(location *ast.Node, moduleReference stri
14421
14421
var sourceFile *ast.SourceFile
14422
14422
resolvedModule := c.program.GetResolvedModule(importingSourceFile, moduleReference, mode)
14423
14423
if resolvedModule.IsResolved() {
14424
- sourceFile = c.program.GetSourceFile (resolvedModule.ResolvedFileName)
14424
+ sourceFile = c.program.GetSourceFileForResolvedModule (resolvedModule.ResolvedFileName)
14425
14425
}
14426
14426
14427
14427
if sourceFile != nil {
@@ -14527,6 +14527,21 @@ func (c *Checker) resolveExternalModule(location *ast.Node, moduleReference stri
14527
14527
}
14528
14528
14529
14529
if moduleNotFoundError != nil {
14530
+
14531
+ // See if this was possibly a projectReference redirect
14532
+ if resolvedModule.IsResolved() {
14533
+ redirect := c.program.GetOutputAndProjectReference(tspath.ToPath(resolvedModule.ResolvedFileName, c.program.GetCurrentDirectory(), c.program.UseCaseSensitiveFileNames()))
14534
+ if redirect != nil && redirect.OutputDts != "" {
14535
+ c.error(
14536
+ errorNode,
14537
+ diagnostics.Output_file_0_has_not_been_built_from_source_file_1,
14538
+ redirect.OutputDts,
14539
+ resolvedModule.ResolvedFileName,
14540
+ )
14541
+ return nil
14542
+ }
14543
+ }
14544
+
14530
14545
// !!!
14531
14546
isExtensionlessRelativePathImport := tspath.PathIsRelative(moduleReference) && !tspath.HasExtension(moduleReference)
14532
14547
resolutionIsNode16OrNext := c.moduleResolutionKind == core.ModuleResolutionKindNode16 || c.moduleResolutionKind == core.ModuleResolutionKindNodeNext
0 commit comments