@azerothjs/typescript-plugin 0.5.0-beta.2 → 0.6.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +69 -62
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -25,9 +25,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
25
25
|
// src/decorate.ts
|
|
26
26
|
var import_node_path = __toESM(require("node:path"));
|
|
27
27
|
|
|
28
|
-
// ../language-service/src/ts-project.ts
|
|
29
|
-
var import_typescript = __toESM(require("typescript"), 1);
|
|
30
|
-
|
|
31
28
|
// ../compiler/src/scanner.ts
|
|
32
29
|
function isWhitespace(ch) {
|
|
33
30
|
return ch === " " || ch === " " || ch === "\n" || ch === "\r" || ch === "\f" || ch === "\v";
|
|
@@ -739,6 +736,16 @@ var CodeMapping = class _CodeMapping {
|
|
|
739
736
|
}
|
|
740
737
|
};
|
|
741
738
|
|
|
739
|
+
// ../language-service/src/perf.ts
|
|
740
|
+
var enabled = false;
|
|
741
|
+
var timings = {};
|
|
742
|
+
function isEnabled() {
|
|
743
|
+
return enabled;
|
|
744
|
+
}
|
|
745
|
+
function record(label, ms) {
|
|
746
|
+
timings[label] = ms;
|
|
747
|
+
}
|
|
748
|
+
|
|
742
749
|
// ../language-service/src/virtual-code.ts
|
|
743
750
|
var RUNTIME_MODULE = "@azerothjs/core";
|
|
744
751
|
var BUILTIN_COMPONENTS = [
|
|
@@ -782,6 +789,15 @@ var Builder = class {
|
|
|
782
789
|
}
|
|
783
790
|
};
|
|
784
791
|
function generateVirtualCode(source) {
|
|
792
|
+
if (!isEnabled()) {
|
|
793
|
+
return buildVirtualCode(source);
|
|
794
|
+
}
|
|
795
|
+
const start = performance.now();
|
|
796
|
+
const result = buildVirtualCode(source);
|
|
797
|
+
record("virtualCode", performance.now() - start);
|
|
798
|
+
return result;
|
|
799
|
+
}
|
|
800
|
+
function buildVirtualCode(source) {
|
|
785
801
|
const builder = new Builder(source);
|
|
786
802
|
const usedBuiltins = /* @__PURE__ */ new Set();
|
|
787
803
|
const collect = (node) => walkComponentTags(node, (tag) => {
|
|
@@ -927,8 +943,13 @@ function generateVirtualCode(source) {
|
|
|
927
943
|
if (node.isComponent) {
|
|
928
944
|
const tagStart = node.start + 1;
|
|
929
945
|
builder.copy(tagStart, tagStart + node.tag.length, "tag");
|
|
946
|
+
const childrenThunk = emitComponentChildren(node.children);
|
|
947
|
+
if (node.attributes.length === 0 && childrenThunk === null) {
|
|
948
|
+
builder.emit("()");
|
|
949
|
+
return;
|
|
950
|
+
}
|
|
930
951
|
builder.emit("(");
|
|
931
|
-
emitProps(node.attributes,
|
|
952
|
+
emitProps(node.attributes, childrenThunk, false);
|
|
932
953
|
builder.emit(")");
|
|
933
954
|
return;
|
|
934
955
|
}
|
|
@@ -1028,43 +1049,34 @@ function quoteString(value) {
|
|
|
1028
1049
|
return `'${value.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/\n/g, "\\n")}'`;
|
|
1029
1050
|
}
|
|
1030
1051
|
|
|
1031
|
-
// ../language-service/src/ts-project.ts
|
|
1032
|
-
var VIRTUAL_SUFFIX = ".azeroth.ts";
|
|
1033
|
-
function isVirtualFile(fileName) {
|
|
1034
|
-
return fileName.endsWith(VIRTUAL_SUFFIX);
|
|
1035
|
-
}
|
|
1036
|
-
function toVirtualFile(azerothPath) {
|
|
1037
|
-
return `${azerothPath}.ts`;
|
|
1038
|
-
}
|
|
1039
|
-
function toAzerothPath(virtualFile) {
|
|
1040
|
-
return virtualFile.slice(0, -3);
|
|
1041
|
-
}
|
|
1042
|
-
|
|
1043
1052
|
// src/decorate.ts
|
|
1044
1053
|
var AZEROTH_EXT = ".azeroth";
|
|
1045
1054
|
function isAzerothSpecifier(text) {
|
|
1046
1055
|
return text.endsWith(AZEROTH_EXT) && (text.startsWith(".") || text.startsWith("/"));
|
|
1047
1056
|
}
|
|
1048
|
-
function
|
|
1057
|
+
function isAzerothFile(fileName) {
|
|
1058
|
+
return fileName.endsWith(AZEROTH_EXT);
|
|
1059
|
+
}
|
|
1060
|
+
function scriptKindFromName(ts, fileName) {
|
|
1049
1061
|
if (fileName.endsWith(".tsx")) {
|
|
1050
|
-
return
|
|
1062
|
+
return ts.ScriptKind.TSX;
|
|
1051
1063
|
}
|
|
1052
1064
|
if (fileName.endsWith(".jsx")) {
|
|
1053
|
-
return
|
|
1065
|
+
return ts.ScriptKind.JSX;
|
|
1054
1066
|
}
|
|
1055
1067
|
if (fileName.endsWith(".json")) {
|
|
1056
|
-
return
|
|
1068
|
+
return ts.ScriptKind.JSON;
|
|
1057
1069
|
}
|
|
1058
1070
|
if (/\.(?:m|c)?js$/.test(fileName)) {
|
|
1059
|
-
return
|
|
1071
|
+
return ts.ScriptKind.JS;
|
|
1060
1072
|
}
|
|
1061
|
-
return
|
|
1073
|
+
return ts.ScriptKind.TS;
|
|
1062
1074
|
}
|
|
1063
1075
|
function resolveSibling(containingFile, specifier) {
|
|
1064
1076
|
return import_node_path.default.resolve(import_node_path.default.dirname(containingFile), specifier).replace(/\\/g, "/");
|
|
1065
1077
|
}
|
|
1066
|
-
function decorateLanguageServiceHost(
|
|
1067
|
-
const read = options.readAzeroth ?? ((azerothPath) =>
|
|
1078
|
+
function decorateLanguageServiceHost(ts, host, options = {}) {
|
|
1079
|
+
const read = options.readAzeroth ?? ((azerothPath) => ts.sys.readFile(azerothPath));
|
|
1068
1080
|
const cache = /* @__PURE__ */ new Map();
|
|
1069
1081
|
const virtualCodeFor = (azerothPath) => {
|
|
1070
1082
|
const source = read(azerothPath);
|
|
@@ -1081,57 +1093,52 @@ function decorateLanguageServiceHost(ts2, host, options = {}) {
|
|
|
1081
1093
|
};
|
|
1082
1094
|
const origSnapshot = host.getScriptSnapshot?.bind(host);
|
|
1083
1095
|
host.getScriptSnapshot = (fileName) => {
|
|
1084
|
-
if (
|
|
1085
|
-
const code = virtualCodeFor(
|
|
1086
|
-
return code === void 0 ? void 0 :
|
|
1096
|
+
if (isAzerothFile(fileName)) {
|
|
1097
|
+
const code = virtualCodeFor(fileName);
|
|
1098
|
+
return code === void 0 ? void 0 : ts.ScriptSnapshot.fromString(code);
|
|
1087
1099
|
}
|
|
1088
1100
|
return origSnapshot ? origSnapshot(fileName) : void 0;
|
|
1089
1101
|
};
|
|
1090
1102
|
const origKind = host.getScriptKind?.bind(host);
|
|
1091
1103
|
host.getScriptKind = (fileName) => {
|
|
1092
|
-
if (
|
|
1093
|
-
return
|
|
1094
|
-
}
|
|
1095
|
-
return origKind ? origKind(fileName) : scriptKindFromName(ts2, fileName);
|
|
1096
|
-
};
|
|
1097
|
-
const origVersion = host.getScriptVersion.bind(host);
|
|
1098
|
-
host.getScriptVersion = (fileName) => {
|
|
1099
|
-
if (isVirtualFile(fileName)) {
|
|
1100
|
-
const azerothPath = toAzerothPath(fileName);
|
|
1101
|
-
const mtime = ts2.sys.getModifiedTime?.(azerothPath)?.getTime() ?? 0;
|
|
1102
|
-
return `azeroth:${mtime}`;
|
|
1103
|
-
}
|
|
1104
|
-
return origVersion(fileName);
|
|
1105
|
-
};
|
|
1106
|
-
const origExists = host.fileExists?.bind(host);
|
|
1107
|
-
host.fileExists = (fileName) => {
|
|
1108
|
-
if (isVirtualFile(fileName)) {
|
|
1109
|
-
return read(toAzerothPath(fileName)) !== void 0;
|
|
1104
|
+
if (isAzerothFile(fileName)) {
|
|
1105
|
+
return ts.ScriptKind.TS;
|
|
1110
1106
|
}
|
|
1111
|
-
return
|
|
1107
|
+
return origKind ? origKind(fileName) : scriptKindFromName(ts, fileName);
|
|
1112
1108
|
};
|
|
1113
1109
|
const origReadFile = host.readFile?.bind(host);
|
|
1114
1110
|
host.readFile = (fileName, encoding) => {
|
|
1115
|
-
if (
|
|
1116
|
-
return virtualCodeFor(
|
|
1111
|
+
if (isAzerothFile(fileName)) {
|
|
1112
|
+
return virtualCodeFor(fileName);
|
|
1117
1113
|
}
|
|
1118
|
-
return origReadFile ? origReadFile(fileName, encoding) :
|
|
1114
|
+
return origReadFile ? origReadFile(fileName, encoding) : ts.sys.readFile(fileName, encoding);
|
|
1119
1115
|
};
|
|
1120
1116
|
const origResolve = host.resolveModuleNameLiterals?.bind(host);
|
|
1121
1117
|
host.resolveModuleNameLiterals = (literals, containingFile, redirectedReference, compilerOptions, containingSourceFile, reusedNames) => {
|
|
1122
|
-
const base = origResolve ? origResolve(literals, containingFile, redirectedReference, compilerOptions, containingSourceFile, reusedNames) : literals.map((literal) =>
|
|
1118
|
+
const base = origResolve ? origResolve(literals, containingFile, redirectedReference, compilerOptions, containingSourceFile, reusedNames) : literals.map((literal) => ts.resolveModuleName(literal.text, containingFile, compilerOptions, host));
|
|
1119
|
+
const asAzeroth = (azerothPath) => ({
|
|
1120
|
+
resolvedModule: {
|
|
1121
|
+
// The REAL `.azeroth` path, reported with a `.ts` module
|
|
1122
|
+
// extension so TypeScript treats it as a TypeScript module. Its
|
|
1123
|
+
// snapshot (above) is the compiled virtual code.
|
|
1124
|
+
resolvedFileName: azerothPath,
|
|
1125
|
+
extension: ts.Extension.Ts,
|
|
1126
|
+
isExternalLibraryImport: false
|
|
1127
|
+
}
|
|
1128
|
+
});
|
|
1123
1129
|
return literals.map((literal, index) => {
|
|
1124
|
-
|
|
1125
|
-
|
|
1130
|
+
const text = literal.text;
|
|
1131
|
+
if (isAzerothSpecifier(text)) {
|
|
1132
|
+
const azerothPath = resolveSibling(containingFile, text);
|
|
1133
|
+
if (read(azerothPath) !== void 0) {
|
|
1134
|
+
return asAzeroth(azerothPath);
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
const relative = text.startsWith(".") || text.startsWith("/");
|
|
1138
|
+
if (!base[index].resolvedModule && relative && !text.endsWith(AZEROTH_EXT)) {
|
|
1139
|
+
const azerothPath = resolveSibling(containingFile, text + AZEROTH_EXT);
|
|
1126
1140
|
if (read(azerothPath) !== void 0) {
|
|
1127
|
-
return
|
|
1128
|
-
resolvedModule: {
|
|
1129
|
-
resolvedFileName: toVirtualFile(azerothPath),
|
|
1130
|
-
extension: ts2.Extension.Ts,
|
|
1131
|
-
isExternalLibraryImport: false
|
|
1132
|
-
},
|
|
1133
|
-
failedLookupLocations: []
|
|
1134
|
-
};
|
|
1141
|
+
return asAzeroth(azerothPath);
|
|
1135
1142
|
}
|
|
1136
1143
|
}
|
|
1137
1144
|
return base[index];
|
|
@@ -1141,10 +1148,10 @@ function decorateLanguageServiceHost(ts2, host, options = {}) {
|
|
|
1141
1148
|
|
|
1142
1149
|
// src/index.ts
|
|
1143
1150
|
function init(modules) {
|
|
1144
|
-
const
|
|
1151
|
+
const ts = modules.typescript;
|
|
1145
1152
|
return {
|
|
1146
1153
|
create(info) {
|
|
1147
|
-
decorateLanguageServiceHost(
|
|
1154
|
+
decorateLanguageServiceHost(ts, info.languageServiceHost);
|
|
1148
1155
|
info.project.projectService.logger.info("[azerothjs] typescript-plugin: .azeroth module resolution enabled");
|
|
1149
1156
|
return info.languageService;
|
|
1150
1157
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@azerothjs/typescript-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0-beta.1",
|
|
4
4
|
"description": "AzerothJS TypeScript language-service plugin — resolves .azeroth imports with real types in tsserver/editors",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"files":
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
],
|
|
23
23
|
"devDependencies":
|
|
24
24
|
{
|
|
25
|
-
"@azerothjs/language-service": "0.
|
|
25
|
+
"@azerothjs/language-service": "0.6.0-beta.1",
|
|
26
26
|
"esbuild": "^0.28.0"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies":
|