Skip to content

Upgrade to TS 5.7.3 #15

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

Closed
wants to merge 14 commits into from
28 changes: 1 addition & 27 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1551,37 +1551,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
mergeSymbol,
});

const nodeGlobalThisSymbol = createSymbol(SymbolFlags.Module, "globalThis" as __String, CheckFlags.Readonly);
var nodeGlobalThisSymbol = createSymbol(SymbolFlags.Module, "globalThis" as __String, CheckFlags.Readonly);
nodeGlobalThisSymbol.exports = denoContext.combinedGlobals;
nodeGlobalThisSymbol.declarations = [];
nodeGlobals.set(nodeGlobalThisSymbol.escapedName, nodeGlobalThisSymbol);

// deno: huge hacks to get @types/node to work
nodeGlobals.set(
"onmessage" as __String,
createSymbol(SymbolFlags.Module, "onmessage" as __String, CheckFlags.Readonly),
);
nodeGlobals.set(
"onabort" as __String,
createSymbol(SymbolFlags.Module, "onabort" as __String, CheckFlags.Readonly),
);
nodeGlobals.set(
"ReportingObserver" as __String,
createSymbol(SymbolFlags.Module, "ReportingObserver" as __String, CheckFlags.Readonly),
);
nodeGlobals.set(
"PerformanceObserver" as __String,
createSymbol(SymbolFlags.Module, "PerformanceObserver" as __String, CheckFlags.Readonly),
);
nodeGlobals.set(
"PerformanceObserverEntryList" as __String,
createSymbol(SymbolFlags.Module, "PerformanceObserverEntryList" as __String, CheckFlags.Readonly),
);
nodeGlobals.set(
"PerformanceResourceTiming" as __String,
createSymbol(SymbolFlags.Module, "PerformanceResourceTiming" as __String, CheckFlags.Readonly),
);

var argumentsSymbol = createSymbol(SymbolFlags.Property, "arguments" as __String);
var requireSymbol = createSymbol(SymbolFlags.Property, "require" as __String);
var isolatedModulesLikeFlagName = compilerOptions.verbatimModuleSyntax ? "verbatimModuleSyntax" : "isolatedModules";
Expand Down
40 changes: 37 additions & 3 deletions src/compiler/deno.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import * as ts from "./_namespaces/ts";
import * as ts from "./_namespaces/ts.js";

export type IsNodeSourceFileCallback = (sourceFile: ts.SourceFile) => boolean;

let isNodeSourceFile: IsNodeSourceFileCallback = () => false;
let nodeOnlyGlobalNames = new Set<ts.__String>();
let typesNodeIgnorableNames = new Set<ts.__String>();

export function setIsNodeSourceFileCallback(callback: IsNodeSourceFileCallback): void {
isNodeSourceFile = callback;
}

export function setNodeOnlyGlobalNames(names: readonly string[]): void {
nodeOnlyGlobalNames = new Set(names) as Set<ts.__String>;
export function setNodeOnlyGlobalNames(names: Set<string>): void {
nodeOnlyGlobalNames = names as Set<ts.__String>;
}

export function setTypesNodeIgnorableNames(names: Set<string>): void {
typesNodeIgnorableNames = names as Set<ts.__String>;
}

// When upgrading:
Expand Down Expand Up @@ -54,13 +59,42 @@ export function createDenoForkContext({
function mergeGlobalSymbolTable(node: ts.Node, source: ts.SymbolTable, unidirectional = false) {
const sourceFile = ts.getSourceFileOfNode(node);
const isNodeFile = hasNodeSourceFile(sourceFile);
const isTypesNodeSourceFile = isNodeFile && isTypesNodePkgPath(sourceFile.path);
source.forEach((sourceSymbol, id) => {
const target = isNodeFile ? getGlobalsForName(id) : globals;
const targetSymbol = target.get(id);
if (
isTypesNodeSourceFile
&& targetSymbol !== undefined
&& typesNodeIgnorableNames.has(id)
// if the symbol has a @types/node package then that means the global
// was created within the @types/node package and not the lib.d.ts files,
// so allow merging to it (useful when someone has DOM and deno types disabled)
&& !symbolHasAnyTypesNodePkgDecl(targetSymbol)
) {
return;
}
target.set(id, targetSymbol ? mergeSymbol(targetSymbol, sourceSymbol, unidirectional) : sourceSymbol);
});
}

function symbolHasAnyTypesNodePkgDecl(symbol: ts.Symbol) {
if (symbol.declarations) {
for (const decl of symbol.declarations) {
const sourceFile = ts.getSourceFileOfNode(decl);
const isNodeFile = hasNodeSourceFile(sourceFile);
if (isNodeFile && isTypesNodePkgPath(sourceFile.path)) {
return true;
}
}
}
return false;
}

function isTypesNodePkgPath(path: ts.Path) {
return path.endsWith(".d.ts") && path.includes("/@types/node/");
}

function createNodeGlobalsSymbolTable() {
return new Proxy(globals, {
get(target, prop: string | symbol, receiver) {
Expand Down
4 changes: 0 additions & 4 deletions src/typescript/_namespaces/ts.server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
/* Generated file to emulate the ts.server namespace. */

export * from "../../jsTyping/_namespaces/ts.server.js";
export * from "../../server/_namespaces/ts.server.js";
5 changes: 1 addition & 4 deletions src/typescript/_namespaces/ts.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
/* Generated file to emulate the ts namespace. */

export * from "../../compiler/_namespaces/ts.js";
export * from "../../jsTyping/_namespaces/ts.js";
export * from "../../services/_namespaces/ts.js";
export * from "../../server/_namespaces/ts.js";
import * as server from "./ts.server.js";
export { server };

4 changes: 1 addition & 3 deletions src/typescript/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
},
"references": [
{ "path": "../compiler" },
{ "path": "../jsTyping" },
{ "path": "../services" },
{ "path": "../server" }
{ "path": "../services" }
],
"include": ["**/*"]
}