Skip to content

Commit 7593f9e

Browse files
authored
Misc fixes (#2112)
1 parent 2f16c3c commit 7593f9e

21 files changed

+112
-129
lines changed

internal/ast/kind.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,6 @@ const (
339339
KindEnumMember
340340
// Top-level nodes
341341
KindSourceFile
342-
KindBundle
343342
// JSDoc nodes
344343
KindJSDocTypeExpression
345344
KindJSDocNameReference

internal/ast/kind_stringer_generated.go

Lines changed: 49 additions & 50 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/binder/binder.go

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,9 @@ func (b *Binder) bind(node *ast.Node) bool {
683683
case ast.KindInterfaceDeclaration:
684684
b.bindBlockScopedDeclaration(node, ast.SymbolFlagsInterface, ast.SymbolFlagsInterfaceExcludes)
685685
case ast.KindCallExpression:
686-
b.bindCallExpression(node)
686+
if ast.IsInJSFile(node) {
687+
b.bindCallExpression(node)
688+
}
687689
case ast.KindTypeAliasDeclaration, ast.KindJSTypeAliasDeclaration:
688690
b.bindBlockScopedDeclaration(node, ast.SymbolFlagsTypeAlias, ast.SymbolFlagsTypeAliasExcludes)
689691
case ast.KindEnumDeclaration:
@@ -910,16 +912,24 @@ func (b *Binder) bindFunctionExpression(node *ast.Node) {
910912
}
911913

912914
func (b *Binder) bindCallExpression(node *ast.Node) {
913-
// !!! for ModuleDetectionKind.Force, external module indicator is forced to `true` in Strada for source files, in which case
914-
// we should set the commonjs module indicator but not call b.bindSourceFileAsExternalModule
915-
// !!! && file.externalModuleIndicator !== true (used for ModuleDetectionKind.Force)
916-
if ast.IsInJSFile(node) &&
917-
b.file.ExternalModuleIndicator == nil &&
918-
b.file.CommonJSModuleIndicator == nil &&
919-
ast.IsRequireCall(node, false /*requireStringLiteralLikeArgument*/) {
915+
// We're only inspecting call expressions to detect CommonJS modules, so we can skip
916+
// this check if we've already seen the module indicator
917+
if b.file.CommonJSModuleIndicator == nil && ast.IsRequireCall(node, false /*requireStringLiteralLikeArgument*/) {
918+
b.setCommonJSModuleIndicator(node)
919+
}
920+
}
921+
922+
func (b *Binder) setCommonJSModuleIndicator(node *ast.Node) bool {
923+
if b.file.ExternalModuleIndicator != nil && b.file.ExternalModuleIndicator != b.file.AsNode() {
924+
return false
925+
}
926+
if b.file.CommonJSModuleIndicator == nil {
920927
b.file.CommonJSModuleIndicator = node
921-
b.bindSourceFileAsExternalModule()
928+
if b.file.ExternalModuleIndicator == nil {
929+
b.bindSourceFileAsExternalModule()
930+
}
922931
}
932+
return true
923933
}
924934

925935
func (b *Binder) bindClassLikeDeclaration(node *ast.Node) {

internal/checker/grammarchecks.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2093,9 +2093,7 @@ func (c *Checker) checkGrammarNumericLiteral(node *ast.NumericLiteral) {
20932093
// We should test against `getTextOfNode(node)` rather than `node.text`, because `node.text` for large numeric literals can contain "."
20942094
// e.g. `node.text` for numeric literal `1100000000000000000000` is `1.1e21`.
20952095
isFractional := strings.ContainsRune(nodeText, '.')
2096-
// !!!
2097-
// isScientific := node.NumericLiteralFlags & ast.TokenFlagsScientific
2098-
isScientific := strings.ContainsRune(nodeText, 'e')
2096+
isScientific := node.TokenFlags&ast.TokenFlagsScientific != 0
20992097

21002098
// Scientific notation (e.g. 2e54 and 1e00000000010) can't be converted to bigint
21012099
// Fractional numbers (e.g. 9000000000000000.001) are inherently imprecise anyway

internal/checker/nodebuilderimpl.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,7 +1179,6 @@ func (b *NodeBuilderImpl) getSpecifierForModuleSymbol(symbol *ast.Symbol, overri
11791179
if ok {
11801180
return result
11811181
}
1182-
isBundle := false // !!! remove me
11831182
// For declaration bundles, we need to generate absolute paths relative to the common source dir for imports,
11841183
// just like how the declaration emitter does for the ambient module declarations - we can easily accomplish this
11851184
// using the `baseUrl` compiler option (which we would otherwise never use in declaration emit) and a non-relative
@@ -1191,13 +1190,6 @@ func (b *NodeBuilderImpl) getSpecifierForModuleSymbol(symbol *ast.Symbol, overri
11911190
if resolutionMode == core.ResolutionModeESM {
11921191
endingPref = modulespecifiers.ImportModuleSpecifierEndingPreferenceJs
11931192
}
1194-
if isBundle {
1195-
// !!! relies on option cloning and specifier host implementation
1196-
// specifierCompilerOptions = &core.CompilerOptions{BaseUrl: host.CommonSourceDirectory()}
1197-
// TODO: merge with b.ch.compilerOptions
1198-
specifierPref = modulespecifiers.ImportModuleSpecifierPreferenceNonRelative
1199-
endingPref = modulespecifiers.ImportModuleSpecifierEndingPreferenceMinimal
1200-
}
12011193

12021194
allSpecifiers := modulespecifiers.GetModuleSpecifiers(
12031195
symbol,

internal/evaluator/evaluator.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ func evaluateTemplateExpression(expr *ast.Node, location *ast.Node, evaluate Eva
140140
}
141141

142142
func AnyToString(v any) string {
143-
// !!! This function should behave identically to the expression `"" + v` in JS
144143
switch v := v.(type) {
145144
case string:
146145
return v
@@ -155,7 +154,6 @@ func AnyToString(v any) string {
155154
}
156155

157156
func IsTruthy(v any) bool {
158-
// !!! This function should behave identically to the expression `!!v` in JS
159157
switch v := v.(type) {
160158
case string:
161159
return len(v) != 0

internal/execute/tsc.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323

2424
func CommandLine(sys tsc.System, commandLineArgs []string, testing tsc.CommandLineTesting) tsc.CommandLineResult {
2525
if len(commandLineArgs) > 0 {
26-
// !!! build mode
2726
switch strings.ToLower(commandLineArgs[0]) {
2827
case "-b", "--b", "-build", "--build":
2928
return tscBuildCompilation(sys, tsoptions.ParseBuildCommandLine(commandLineArgs, sys), testing)

internal/outputpaths/outputpaths.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ func (o *OutputPaths) DeclarationMapPath() string {
4040
}
4141

4242
func GetOutputPathsFor(sourceFile *ast.SourceFile, options *core.CompilerOptions, host OutputPathsHost, forceDtsEmit bool) *OutputPaths {
43-
// !!! bundle not implemented, may be deprecated
4443
ownOutputFilePath := getOwnEmitOutputFilePath(sourceFile.FileName(), options, host, GetOutputExtension(sourceFile.FileName(), options.Jsx))
4544
isJsonFile := ast.IsJsonSourceFile(sourceFile)
4645
// If json file emits to the same location skip writing it, if emitDeclarationOnly skip writing it

internal/parser/parser.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6457,7 +6457,7 @@ func (p *Parser) processPragmasIntoFields(context *ast.SourceFile) {
64576457
case typesOk:
64586458
var parsed core.ResolutionMode
64596459
if resolutionModeOk {
6460-
parsed = parseResolutionMode(resolutionMode.Value, resolutionMode.Pos(), resolutionMode.End() /*, reportDiagnostic*/)
6460+
parsed = p.parseResolutionMode(resolutionMode.Value, resolutionMode.Pos(), resolutionMode.End())
64616461
}
64626462
context.TypeReferenceDirectives = append(context.TypeReferenceDirectives, &ast.FileReference{
64636463
TextRange: types.TextRange,
@@ -6498,16 +6498,17 @@ func (p *Parser) processPragmasIntoFields(context *ast.SourceFile) {
64986498
}
64996499
}
65006500

6501-
func parseResolutionMode(mode string, pos int, end int /*reportDiagnostic: PragmaDiagnosticReporter*/) (resolutionKind core.ResolutionMode) {
6501+
func (p *Parser) parseResolutionMode(mode string, pos int, end int) (resolutionKind core.ResolutionMode) {
65026502
if mode == "import" {
65036503
resolutionKind = core.ModuleKindESNext
6504+
return resolutionKind
65046505
}
65056506
if mode == "require" {
65066507
resolutionKind = core.ModuleKindCommonJS
6508+
return resolutionKind
65076509
}
6510+
p.parseErrorAt(pos, end, diagnostics.X_resolution_mode_should_be_either_require_or_import)
65086511
return resolutionKind
6509-
// reportDiagnostic(pos, end - pos, Diagnostics.resolution_mode_should_be_either_require_or_import);
6510-
// return undefined;
65116512
}
65126513

65136514
func (p *Parser) jsErrorAtRange(loc core.TextRange, message *diagnostics.Message, args ...any) {

internal/printer/printer.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4951,9 +4951,6 @@ func (p *Printer) Write(node *ast.Node, sourceFile *ast.SourceFile, writer EmitT
49514951
case ast.KindSourceFile:
49524952
p.emitSourceFile(node.AsSourceFile())
49534953

4954-
case ast.KindBundle:
4955-
panic("not implemented")
4956-
49574954
// Transformation nodes
49584955
case ast.KindNotEmittedTypeElement:
49594956
p.emitNotEmittedTypeElement(node.AsNotEmittedTypeElement())

0 commit comments

Comments
 (0)