Skip to content

Feature implementation from commits e29f35a..a8d79ee #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: feature-base-branch-3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion _packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@
},
"dependencies": {
"@typescript/ast": "1.0.0",
"libsyncrpc": "github:microsoft/libsyncrpc#bb02d84"
"@typescript/libsyncrpc": "github:microsoft/libsyncrpc#8cdae454cc482536c5844bef83b796f95464da85"
}
}
2 changes: 1 addition & 1 deletion _packages/api/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SyncRpcChannel } from "libsyncrpc";
import { SyncRpcChannel } from "@typescript/libsyncrpc";
import type { FileSystem } from "./fs.ts";

export interface ClientOptions {
Expand Down
2 changes: 0 additions & 2 deletions internal/ast/nodeflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ const (
NodeFlagsJsonFile NodeFlags = 1 << 25 // If node was parsed in a Json
NodeFlagsDeprecated NodeFlags = 1 << 26 // If has '@deprecated' JSDoc tag

NodeFlagsSkipDirectInference NodeFlags = 1 << 27 // If the node should skip direct type inference.

NodeFlagsBlockScoped = NodeFlagsLet | NodeFlagsConst | NodeFlagsUsing
NodeFlagsConstant = NodeFlagsConst | NodeFlagsUsing
NodeFlagsAwaitUsing = NodeFlagsConst | NodeFlagsUsing // Variable declaration (NOTE: on a single node these flags would otherwise be mutually exclusive)
Expand Down
2 changes: 1 addition & 1 deletion internal/ast/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -1611,7 +1611,7 @@ func IsEffectiveExternalModule(node *SourceFile, compilerOptions *core.CompilerO
}

func isCommonJSContainingModuleKind(kind core.ModuleKind) bool {
return kind == core.ModuleKindCommonJS || kind == core.ModuleKindNode16 || kind == core.ModuleKindNodeNext
return kind == core.ModuleKindCommonJS || core.ModuleKindNode16 <= kind && kind <= core.ModuleKindNodeNext
}

func IsExternalModuleIndicator(node *Statement) bool {
Expand Down
683 changes: 361 additions & 322 deletions internal/checker/checker.go

Large diffs are not rendered by default.

23 changes: 7 additions & 16 deletions internal/checker/emitresolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -900,12 +900,10 @@ func (r *emitResolver) CreateLiteralConstValue(emitContext *printer.EmitContext,
if t.flags&TypeFlagsLiteral == 0 {
return nil // non-literal type
}
literalValue := t.AsLiteralType().value
switch literalValue.(type) {
switch value := t.AsLiteralType().value.(type) {
case string:
return emitContext.Factory.NewStringLiteral(literalValue.(string))
return emitContext.Factory.NewStringLiteral(value)
case jsnum.Number:
value := literalValue.(jsnum.Number)
if value.Abs() != value {
// negative
return emitContext.Factory.NewPrefixUnaryExpression(
Expand All @@ -915,20 +913,13 @@ func (r *emitResolver) CreateLiteralConstValue(emitContext *printer.EmitContext,
}
return emitContext.Factory.NewNumericLiteral(value.String())
case jsnum.PseudoBigInt:
value := literalValue.(jsnum.PseudoBigInt)
if value.Negative {
// negative
return emitContext.Factory.NewPrefixUnaryExpression(
ast.KindMinusToken,
emitContext.Factory.NewBigIntLiteral(value.Base10Value),
)
}
return emitContext.Factory.NewNumericLiteral(value.Base10Value)
return emitContext.Factory.NewBigIntLiteral(pseudoBigIntToString(value) + "n")
case bool:
if literalValue.(bool) {
return emitContext.Factory.NewKeywordExpression(ast.KindTrueKeyword)
kind := ast.KindFalseKeyword
if value {
kind = ast.KindTrueKeyword
}
return emitContext.Factory.NewKeywordExpression(ast.KindFalseKeyword)
return emitContext.Factory.NewKeywordExpression(kind)
}
panic("unhandled literal const value kind")
}
Expand Down
2 changes: 1 addition & 1 deletion internal/checker/nodebuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func (b *NodeBuilder) EmitContext() *printer.EmitContext {
}

func (b *NodeBuilder) enterContext(enclosingDeclaration *ast.Node, flags nodebuilder.Flags, internalFlags nodebuilder.InternalFlags, tracker nodebuilder.SymbolTracker) {
b.ctxStack = append(b.ctxStack, b.impl.ctx)
b.impl.ctx = &NodeBuilderContext{
tracker: tracker,
flags: flags,
Expand All @@ -36,7 +37,6 @@ func (b *NodeBuilder) enterContext(enclosingDeclaration *ast.Node, flags nodebui
tracker = NewSymbolTrackerImpl(b.impl.ctx, nil, b.host)
b.impl.ctx.tracker = tracker
}
b.ctxStack = append(b.ctxStack, b.impl.ctx)
}

func (b *NodeBuilder) popContext() {
Expand Down
17 changes: 8 additions & 9 deletions internal/checker/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,28 +585,27 @@ func (c *Checker) getResolvedSignatureWorker(node *ast.Node, checkMode CheckMode
}

func (c *Checker) GetCandidateSignaturesForStringLiteralCompletions(call *ast.CallLikeExpression, editingArgument *ast.Node) []*Signature {
candidatesSet := collections.Set[*Signature]{}

// first, get candidates when inference is blocked from the source node.
candidates := runWithInferenceBlockedFromSourceNode(c, editingArgument, func() []*Signature {
_, blockedInferenceCandidates := c.getResolvedSignatureWorker(call, CheckModeNormal, 0)
return blockedInferenceCandidates
})
for _, candidate := range candidates {
candidatesSet.Add(candidate)
}
candidatesSet := collections.NewSetFromItems(candidates...)

// next, get candidates where the source node is considered for inference.
candidates = runWithoutResolvedSignatureCaching(c, editingArgument, func() []*Signature {
otherCandidates := runWithoutResolvedSignatureCaching(c, editingArgument, func() []*Signature {
_, inferenceCandidates := c.getResolvedSignatureWorker(call, CheckModeNormal, 0)
return inferenceCandidates
})

for _, candidate := range candidates {
candidatesSet.Add(candidate)
for _, candidate := range otherCandidates {
if candidatesSet.Has(candidate) {
continue
}
candidates = append(candidates, candidate)
}

return slices.Collect(maps.Keys(candidatesSet.Keys()))
return candidates
}

func (c *Checker) GetTypeParameterAtPosition(s *Signature, pos int) *Type {
Expand Down
4 changes: 4 additions & 0 deletions internal/compiler/emitHost.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,7 @@ func (host *emitHost) GetEmitResolver(file *ast.SourceFile, skipDiagnostics bool
defer done()
return checker.GetEmitResolver(file, skipDiagnostics)
}

func (host *emitHost) IsSourceFileFromExternalLibrary(file *ast.SourceFile) bool {
return host.program.IsSourceFileFromExternalLibrary(file)
}
6 changes: 1 addition & 5 deletions internal/compiler/emitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package compiler

import (
"encoding/base64"
"strings"

"github.com/microsoft/typescript-go/internal/ast"
"github.com/microsoft/typescript-go/internal/core"
Expand Down Expand Up @@ -305,10 +304,7 @@ func sourceFileMayBeEmitted(sourceFile *ast.SourceFile, host printer.EmitHost, f
return false
}

// !!! Source file from node_modules are not emitted. In Strada, this depends on module resolution and uses
// `sourceFilesFoundSearchingNodeModules` in `createProgram`. For now, we will just check for `/node_modules/` in
// the file name.
if strings.Contains(sourceFile.FileName(), "/node_modules/") {
if host.IsSourceFileFromExternalLibrary(sourceFile) {
return false
}

Expand Down
Loading