Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
1 change: 0 additions & 1 deletion internal/ast/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,6 @@ const (
KindEnumMember
// Top-level nodes
KindSourceFile
KindBundle
// JSDoc nodes
KindJSDocTypeExpression
KindJSDocNameReference
Expand Down
99 changes: 49 additions & 50 deletions internal/ast/kind_stringer_generated.go

Large diffs are not rendered by default.

28 changes: 19 additions & 9 deletions internal/binder/binder.go
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,9 @@ func (b *Binder) bind(node *ast.Node) bool {
case ast.KindInterfaceDeclaration:
b.bindBlockScopedDeclaration(node, ast.SymbolFlagsInterface, ast.SymbolFlagsInterfaceExcludes)
case ast.KindCallExpression:
b.bindCallExpression(node)
if ast.IsInJSFile(node) {
b.bindCallExpression(node)
}
case ast.KindTypeAliasDeclaration, ast.KindJSTypeAliasDeclaration:
b.bindBlockScopedDeclaration(node, ast.SymbolFlagsTypeAlias, ast.SymbolFlagsTypeAliasExcludes)
case ast.KindEnumDeclaration:
Expand Down Expand Up @@ -910,16 +912,24 @@ func (b *Binder) bindFunctionExpression(node *ast.Node) {
}

func (b *Binder) bindCallExpression(node *ast.Node) {
// !!! for ModuleDetectionKind.Force, external module indicator is forced to `true` in Strada for source files, in which case
// we should set the commonjs module indicator but not call b.bindSourceFileAsExternalModule
// !!! && file.externalModuleIndicator !== true (used for ModuleDetectionKind.Force)
if ast.IsInJSFile(node) &&
b.file.ExternalModuleIndicator == nil &&
b.file.CommonJSModuleIndicator == nil &&
ast.IsRequireCall(node, false /*requireStringLiteralLikeArgument*/) {
// We're only inspecting call expressions to detect CommonJS modules, so we can skip
// this check if we've already seen the module indicator
if b.file.CommonJSModuleIndicator == nil && ast.IsRequireCall(node, false /*requireStringLiteralLikeArgument*/) {
b.setCommonJsModuleIndicator(node)
}
}

func (b *Binder) setCommonJsModuleIndicator(node *ast.Node) bool {
if b.file.ExternalModuleIndicator != nil && b.file.ExternalModuleIndicator != b.file.AsNode() {
return false
}
if b.file.CommonJSModuleIndicator == nil {
b.file.CommonJSModuleIndicator = node
b.bindSourceFileAsExternalModule()
if b.file.ExternalModuleIndicator == nil {
b.bindSourceFileAsExternalModule()
}
}
return true
}

func (b *Binder) bindClassLikeDeclaration(node *ast.Node) {
Expand Down
4 changes: 1 addition & 3 deletions internal/checker/grammarchecks.go
Original file line number Diff line number Diff line change
Expand Up @@ -2093,9 +2093,7 @@ func (c *Checker) checkGrammarNumericLiteral(node *ast.NumericLiteral) {
// We should test against `getTextOfNode(node)` rather than `node.text`, because `node.text` for large numeric literals can contain "."
// e.g. `node.text` for numeric literal `1100000000000000000000` is `1.1e21`.
isFractional := strings.ContainsRune(nodeText, '.')
// !!!
// isScientific := node.NumericLiteralFlags & ast.TokenFlagsScientific
isScientific := strings.ContainsRune(nodeText, 'e')
isScientific := node.TokenFlags&ast.TokenFlagsScientific != 0

// Scientific notation (e.g. 2e54 and 1e00000000010) can't be converted to bigint
// Fractional numbers (e.g. 9000000000000000.001) are inherently imprecise anyway
Expand Down
8 changes: 0 additions & 8 deletions internal/checker/nodebuilderimpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,6 @@ func (b *NodeBuilderImpl) getSpecifierForModuleSymbol(symbol *ast.Symbol, overri
if ok {
return result
}
isBundle := false // !!! remove me
// For declaration bundles, we need to generate absolute paths relative to the common source dir for imports,
// just like how the declaration emitter does for the ambient module declarations - we can easily accomplish this
// using the `baseUrl` compiler option (which we would otherwise never use in declaration emit) and a non-relative
Expand All @@ -1191,13 +1190,6 @@ func (b *NodeBuilderImpl) getSpecifierForModuleSymbol(symbol *ast.Symbol, overri
if resolutionMode == core.ResolutionModeESM {
endingPref = modulespecifiers.ImportModuleSpecifierEndingPreferenceJs
}
if isBundle {
// !!! relies on option cloning and specifier host implementation
// specifierCompilerOptions = &core.CompilerOptions{BaseUrl: host.CommonSourceDirectory()}
// TODO: merge with b.ch.compilerOptions
specifierPref = modulespecifiers.ImportModuleSpecifierPreferenceNonRelative
endingPref = modulespecifiers.ImportModuleSpecifierEndingPreferenceMinimal
}

allSpecifiers := modulespecifiers.GetModuleSpecifiers(
symbol,
Expand Down
2 changes: 0 additions & 2 deletions internal/evaluator/evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ func evaluateTemplateExpression(expr *ast.Node, location *ast.Node, evaluate Eva
}

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

func IsTruthy(v any) bool {
// !!! This function should behave identically to the expression `!!v` in JS
switch v := v.(type) {
case string:
return len(v) != 0
Expand Down
1 change: 0 additions & 1 deletion internal/execute/tsc.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (

func CommandLine(sys tsc.System, commandLineArgs []string, testing tsc.CommandLineTesting) tsc.CommandLineResult {
if len(commandLineArgs) > 0 {
// !!! build mode
switch strings.ToLower(commandLineArgs[0]) {
case "-b", "--b", "-build", "--build":
return tscBuildCompilation(sys, tsoptions.ParseBuildCommandLine(commandLineArgs, sys), testing)
Expand Down
1 change: 0 additions & 1 deletion internal/outputpaths/outputpaths.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func (o *OutputPaths) DeclarationMapPath() string {
}

func GetOutputPathsFor(sourceFile *ast.SourceFile, options *core.CompilerOptions, host OutputPathsHost, forceDtsEmit bool) *OutputPaths {
// !!! bundle not implemented, may be deprecated
ownOutputFilePath := getOwnEmitOutputFilePath(sourceFile.FileName(), options, host, GetOutputExtension(sourceFile.FileName(), options.Jsx))
isJsonFile := ast.IsJsonSourceFile(sourceFile)
// If json file emits to the same location skip writing it, if emitDeclarationOnly skip writing it
Expand Down
9 changes: 5 additions & 4 deletions internal/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -6457,7 +6457,7 @@ func (p *Parser) processPragmasIntoFields(context *ast.SourceFile) {
case typesOk:
var parsed core.ResolutionMode
if resolutionModeOk {
parsed = parseResolutionMode(resolutionMode.Value, resolutionMode.Pos(), resolutionMode.End() /*, reportDiagnostic*/)
parsed = p.parseResolutionMode(resolutionMode.Value, resolutionMode.Pos(), resolutionMode.End())
}
context.TypeReferenceDirectives = append(context.TypeReferenceDirectives, &ast.FileReference{
TextRange: types.TextRange,
Expand Down Expand Up @@ -6498,16 +6498,17 @@ func (p *Parser) processPragmasIntoFields(context *ast.SourceFile) {
}
}

func parseResolutionMode(mode string, pos int, end int /*reportDiagnostic: PragmaDiagnosticReporter*/) (resolutionKind core.ResolutionMode) {
func (p *Parser) parseResolutionMode(mode string, pos int, end int) (resolutionKind core.ResolutionMode) {
if mode == "import" {
resolutionKind = core.ModuleKindESNext
return resolutionKind
}
if mode == "require" {
resolutionKind = core.ModuleKindCommonJS
return resolutionKind
}
p.parseErrorAt(pos, end, diagnostics.X_resolution_mode_should_be_either_require_or_import)
return resolutionKind
// reportDiagnostic(pos, end - pos, Diagnostics.resolution_mode_should_be_either_require_or_import);
// return undefined;
}

func (p *Parser) jsErrorAtRange(loc core.TextRange, message *diagnostics.Message, args ...any) {
Expand Down
3 changes: 0 additions & 3 deletions internal/printer/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4951,9 +4951,6 @@ func (p *Printer) Write(node *ast.Node, sourceFile *ast.SourceFile, writer EmitT
case ast.KindSourceFile:
p.emitSourceFile(node.AsSourceFile())

case ast.KindBundle:
panic("not implemented")

// Transformation nodes
case ast.KindNotEmittedTypeElement:
p.emitNotEmittedTypeElement(node.AsNotEmittedTypeElement())
Expand Down
14 changes: 2 additions & 12 deletions internal/transformers/declarations/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ type DeclarationTransformer struct {
declarationFilePath string
declarationMapPath string

isBundledEmit bool
needsDeclare bool
needsScopeFixMarker bool
resultHasScopeMarker bool
Expand Down Expand Up @@ -102,7 +101,6 @@ func (tx *DeclarationTransformer) visit(node *ast.Node) *ast.Node {
if node == nil {
return nil
}
// !!! TODO: Bundle support?
switch node.Kind {
case ast.KindSourceFile:
return tx.visitSourceFile(node.AsSourceFile())
Expand Down Expand Up @@ -161,7 +159,6 @@ func (tx *DeclarationTransformer) visitSourceFile(node *ast.SourceFile) *ast.Nod
return node.AsNode()
}

tx.isBundledEmit = false
tx.needsDeclare = true
tx.needsScopeFixMarker = false
tx.resultHasScopeMarker = false
Expand Down Expand Up @@ -238,7 +235,7 @@ func (tx *DeclarationTransformer) transformAndReplaceLatePaintedStatements(state
tx.state.lateMarkedStatements = tx.state.lateMarkedStatements[1:]

saveNeedsDeclare := tx.needsDeclare
tx.needsDeclare = next.Parent != nil && ast.IsSourceFile(next.Parent) && !(ast.IsExternalModule(next.Parent.AsSourceFile()) && tx.isBundledEmit)
tx.needsDeclare = next.Parent != nil && ast.IsSourceFile(next.Parent)

result := tx.transformTopLevelDeclaration(next)

Expand Down Expand Up @@ -311,8 +308,6 @@ func (tx *DeclarationTransformer) getReferencedFiles(outputFilePath string) (res
if file.IsDeclarationFile {
declFileName = file.FileName()
} else {
// !!! bundled emit support, omit bundled refs
// if (tx.isBundledEmit && contains((node as Bundle).sourceFiles, file)) continue
paths := tx.host.GetOutputPathsFor(file, true)
// Try to use output path for referenced file, or output js path if that doesn't exist, or the input path if all else fails
declFileName = paths.DeclarationFilePath()
Expand Down Expand Up @@ -1047,11 +1042,6 @@ func (tx *DeclarationTransformer) rewriteModuleSpecifier(parent *ast.Node, input
return nil
}
tx.resultHasExternalModuleIndicator = tx.resultHasExternalModuleIndicator || (parent.Kind != ast.KindModuleDeclaration && parent.Kind != ast.KindImportType)
if ast.IsStringLiteralLike(input) {
if tx.isBundledEmit {
// !!! TODO: support bundled emit specifier rewriting
}
}
return input
}

Expand Down Expand Up @@ -1578,7 +1568,7 @@ func (tx *DeclarationTransformer) ensureModifierFlags(node *ast.Node) ast.Modifi
additions = ast.ModifierFlagsAmbient
}
parentIsFile := node.Parent.Kind == ast.KindSourceFile
if !parentIsFile || (tx.isBundledEmit && parentIsFile && ast.IsExternalModule(node.Parent.AsSourceFile())) {
if !parentIsFile {
mask ^= ast.ModifierFlagsAmbient
additions = ast.ModifierFlagsNone
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
}
return path;
};
Object.defineProperty(exports, "__esModule", { value: true });
{
require(__rewriteRelativeImportExtension("" + "./foo.ts"));
import(__rewriteRelativeImportExtension("" + "./foo.ts"));
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/index.ts(1,45): error TS1453: `resolution-mode` should be either `require` or `import`.
/index.ts(2,1): error TS2304: Cannot find name 'foo'.


==== /index.ts (1 errors) ====
==== /index.ts (2 errors) ====
/// <reference types="pkg" resolution-mode="esm"/>
~~~
!!! error TS1453: `resolution-mode` should be either `require` or `import`.
foo; // bad resolution mode, which resolves is arbitrary
~~~
!!! error TS2304: Cannot find name 'foo'.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
+++ new.nodeModulesTripleSlashReferenceModeOverrideModeError(module=node16).errors.txt
@@= skipped -0, +0 lines =@@
-/index.ts(1,23): error TS1453: `resolution-mode` should be either `require` or `import`.
+/index.ts(1,45): error TS1453: `resolution-mode` should be either `require` or `import`.
/index.ts(2,1): error TS2304: Cannot find name 'foo'.


-==== /index.ts (2 errors) ====
+==== /index.ts (1 errors) ====
==== /index.ts (2 errors) ====
/// <reference types="pkg" resolution-mode="esm"/>
- ~~~
-!!! error TS1453: `resolution-mode` should be either `require` or `import`.
+ ~~~
!!! error TS1453: `resolution-mode` should be either `require` or `import`.
foo; // bad resolution mode, which resolves is arbitrary
~~~
!!! error TS2304: Cannot find name 'foo'.
~~~
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/index.ts(1,45): error TS1453: `resolution-mode` should be either `require` or `import`.
/index.ts(2,1): error TS2304: Cannot find name 'foo'.


==== /index.ts (1 errors) ====
==== /index.ts (2 errors) ====
/// <reference types="pkg" resolution-mode="esm"/>
~~~
!!! error TS1453: `resolution-mode` should be either `require` or `import`.
foo; // bad resolution mode, which resolves is arbitrary
~~~
!!! error TS2304: Cannot find name 'foo'.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
+++ new.nodeModulesTripleSlashReferenceModeOverrideModeError(module=node18).errors.txt
@@= skipped -0, +0 lines =@@
-/index.ts(1,23): error TS1453: `resolution-mode` should be either `require` or `import`.
+/index.ts(1,45): error TS1453: `resolution-mode` should be either `require` or `import`.
/index.ts(2,1): error TS2304: Cannot find name 'foo'.


-==== /index.ts (2 errors) ====
+==== /index.ts (1 errors) ====
==== /index.ts (2 errors) ====
/// <reference types="pkg" resolution-mode="esm"/>
- ~~~
-!!! error TS1453: `resolution-mode` should be either `require` or `import`.
+ ~~~
!!! error TS1453: `resolution-mode` should be either `require` or `import`.
foo; // bad resolution mode, which resolves is arbitrary
~~~
!!! error TS2304: Cannot find name 'foo'.
~~~
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/index.ts(1,45): error TS1453: `resolution-mode` should be either `require` or `import`.
/index.ts(2,1): error TS2304: Cannot find name 'foo'.


==== /index.ts (1 errors) ====
==== /index.ts (2 errors) ====
/// <reference types="pkg" resolution-mode="esm"/>
~~~
!!! error TS1453: `resolution-mode` should be either `require` or `import`.
foo; // bad resolution mode, which resolves is arbitrary
~~~
!!! error TS2304: Cannot find name 'foo'.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
+++ new.nodeModulesTripleSlashReferenceModeOverrideModeError(module=node20).errors.txt
@@= skipped -0, +0 lines =@@
-/index.ts(1,23): error TS1453: `resolution-mode` should be either `require` or `import`.
+/index.ts(1,45): error TS1453: `resolution-mode` should be either `require` or `import`.
/index.ts(2,1): error TS2304: Cannot find name 'foo'.


-==== /index.ts (2 errors) ====
+==== /index.ts (1 errors) ====
==== /index.ts (2 errors) ====
/// <reference types="pkg" resolution-mode="esm"/>
- ~~~
-!!! error TS1453: `resolution-mode` should be either `require` or `import`.
+ ~~~
!!! error TS1453: `resolution-mode` should be either `require` or `import`.
foo; // bad resolution mode, which resolves is arbitrary
~~~
!!! error TS2304: Cannot find name 'foo'.
~~~
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/index.ts(1,45): error TS1453: `resolution-mode` should be either `require` or `import`.
/index.ts(2,1): error TS2304: Cannot find name 'foo'.


==== /index.ts (1 errors) ====
==== /index.ts (2 errors) ====
/// <reference types="pkg" resolution-mode="esm"/>
~~~
!!! error TS1453: `resolution-mode` should be either `require` or `import`.
foo; // bad resolution mode, which resolves is arbitrary
~~~
!!! error TS2304: Cannot find name 'foo'.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
+++ new.nodeModulesTripleSlashReferenceModeOverrideModeError(module=nodenext).errors.txt
@@= skipped -0, +0 lines =@@
-/index.ts(1,23): error TS1453: `resolution-mode` should be either `require` or `import`.
+/index.ts(1,45): error TS1453: `resolution-mode` should be either `require` or `import`.
/index.ts(2,1): error TS2304: Cannot find name 'foo'.


-==== /index.ts (2 errors) ====
+==== /index.ts (1 errors) ====
==== /index.ts (2 errors) ====
/// <reference types="pkg" resolution-mode="esm"/>
- ~~~
-!!! error TS1453: `resolution-mode` should be either `require` or `import`.
+ ~~~
!!! error TS1453: `resolution-mode` should be either `require` or `import`.
foo; // bad resolution mode, which resolves is arbitrary
~~~
!!! error TS2304: Cannot find name 'foo'.
~~~
Loading