@gi-tcg/gts-transpiler 0.3.0 → 0.3.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.d.ts CHANGED
@@ -19,12 +19,6 @@ declare class GtsTranspilerError extends Error {
19
19
  readonly position: SourceLocation2 | null;
20
20
  constructor(message: string, position: SourceLocation2 | null);
21
21
  }
22
- interface PathPolyfill {
23
- isAbsolute(filePath: string): boolean;
24
- dirname(filePath: string): string;
25
- resolve(...segments: string[]): string;
26
- }
27
- declare const path: PathPolyfill;
28
22
  interface GtsConfig extends TranspileOption {}
29
23
  type ReadFileFn = (path: string, encoding: "utf8") => string;
30
24
  type ReadFileAsyncFn = (path: string, encoding: "utf8") => Promise<string>;
@@ -42,4 +36,4 @@ declare function resolveGtsConfig(filePath: string, inlineConfig: GtsConfig, opt
42
36
  declare function resolveGtsConfigSync(filePath: string, inlineConfig: GtsConfig, options: ResolveGtsConfigSyncOptions): Required<GtsConfig>;
43
37
  declare function transpile(source: string, filename: string, option: TranspileOption): TranspileResult;
44
38
  declare function transpileForVolar(source: string, filename: string, option: TranspileOption): VolarMappingResult;
45
- export { transpileForVolar, transpile, resolveGtsConfigSync, resolveGtsConfig, path, VolarMappingResult, TranspileResult, TranspileOption, PathPolyfill, GtsTranspilerError, GtsConfig };
39
+ export { transpileForVolar, transpile, resolveGtsConfigSync, resolveGtsConfig, VolarMappingResult, TranspileResult, TranspileOption, GtsTranspilerError, GtsConfig };
package/dist/index.js CHANGED
@@ -281,7 +281,7 @@ function gtsPlugin(options = {}) {
281
281
  return super.parseExprAtom(refDestructuringErrors, forInit, forNew);
282
282
  }
283
283
  parseMaybeUnary(refDestructuringErrors, sawUnary, incDec, forInit) {
284
- if (this.isContextual("query")) {
284
+ if (this.isShortcutContext && this.isContextual("query")) {
285
285
  const expr = this.gts_parseQueryExpression();
286
286
  if (!incDec && this.eat(tokTypes2.starstar)) {
287
287
  this.unexpected(this.lastTokStart);
@@ -952,6 +952,15 @@ var commonGtsVisitor = {
952
952
  type: "Literal",
953
953
  value: !!node.star
954
954
  }
955
+ },
956
+ {
957
+ type: "Property",
958
+ key: { type: "Identifier", name: "context" },
959
+ computed: false,
960
+ kind: "init",
961
+ method: false,
962
+ shorthand: false,
963
+ value: state.fnArgId
955
964
  }
956
965
  ]
957
966
  }
@@ -2173,77 +2182,7 @@ function transform(ast, option = {}, sourceInfo = {}) {
2173
2182
  };
2174
2183
  }
2175
2184
  // packages/transpiler/src/config.ts
2176
- var path = globalThis.require ? globalThis.require("node:path") : {
2177
- isAbsolute(filePath) {
2178
- return filePath.startsWith("/");
2179
- },
2180
- dirname(filePath) {
2181
- if (!filePath) {
2182
- return ".";
2183
- }
2184
- const normalized = normalizeSlashes(filePath);
2185
- if (normalized === "/") {
2186
- return "/";
2187
- }
2188
- const trimmed = normalized.length > 1 && normalized.endsWith("/") ? normalized.slice(0, -1) : normalized;
2189
- const idx = trimmed.lastIndexOf("/");
2190
- if (idx < 0) {
2191
- return ".";
2192
- }
2193
- if (idx === 0) {
2194
- return "/";
2195
- }
2196
- return trimmed.slice(0, idx);
2197
- },
2198
- resolve(...segments) {
2199
- if (segments.length === 0) {
2200
- return ".";
2201
- }
2202
- let resolved = "";
2203
- for (let i = segments.length - 1;i >= 0; i--) {
2204
- const segment = segments[i];
2205
- if (!segment) {
2206
- continue;
2207
- }
2208
- if (resolved) {
2209
- resolved = `${segment}/${resolved}`;
2210
- } else {
2211
- resolved = segment;
2212
- }
2213
- if (path.isAbsolute(segment)) {
2214
- break;
2215
- }
2216
- }
2217
- return normalizeResolvedPath(resolved || ".");
2218
- }
2219
- };
2220
- function normalizeSlashes(filePath) {
2221
- return filePath.replace(/\\+/g, "/");
2222
- }
2223
- function normalizeResolvedPath(filePath) {
2224
- const normalized = normalizeSlashes(filePath);
2225
- const isAbsolute = normalized.startsWith("/");
2226
- const parts = normalized.split("/");
2227
- const stack = [];
2228
- for (const part of parts) {
2229
- if (!part || part === ".") {
2230
- continue;
2231
- }
2232
- if (part === "..") {
2233
- if (stack.length > 0 && stack[stack.length - 1] !== "..") {
2234
- stack.pop();
2235
- } else if (!isAbsolute) {
2236
- stack.push("..");
2237
- }
2238
- continue;
2239
- }
2240
- stack.push(part);
2241
- }
2242
- if (isAbsolute) {
2243
- return `/${stack.join("/")}` || "/";
2244
- }
2245
- return stack.join("/") || ".";
2246
- }
2185
+ import path from "path-browserify-esm";
2247
2186
  var DEFAULT_GTS_CONFIG = {
2248
2187
  runtimeImportSource: "@gi-tcg/gts-runtime",
2249
2188
  providerImportSource: "@gi-tcg/core/gts",
@@ -2347,6 +2286,5 @@ export {
2347
2286
  transpile,
2348
2287
  resolveGtsConfigSync,
2349
2288
  resolveGtsConfig,
2350
- path,
2351
2289
  GtsTranspilerError
2352
2290
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gi-tcg/gts-transpiler",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "repository": "https://github.com/piovium/gts.git",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -22,6 +22,7 @@
22
22
  "acorn": "8.15.0",
23
23
  "esrap": "2.2.1",
24
24
  "magic-string": "^0.30.21",
25
+ "path-browserify-esm": "^1.0.6",
25
26
  "zimmerframe": "^1.1.4"
26
27
  },
27
28
  "devDependencies": {
package/src/config.ts CHANGED
@@ -1,89 +1,5 @@
1
1
  import type { TranspileOption } from "./transform/gts";
2
-
3
- export interface PathPolyfill {
4
- isAbsolute(filePath: string): boolean;
5
- dirname(filePath: string): string;
6
- resolve(...segments: string[]): string;
7
- }
8
-
9
- export const path: PathPolyfill = globalThis.require
10
- ? (globalThis.require("node:path") as typeof import("node:path"))
11
- : {
12
- isAbsolute(filePath) {
13
- return filePath.startsWith("/");
14
- },
15
- dirname(filePath) {
16
- if (!filePath) {
17
- return ".";
18
- }
19
- const normalized = normalizeSlashes(filePath);
20
- if (normalized === "/") {
21
- return "/";
22
- }
23
- const trimmed =
24
- normalized.length > 1 && normalized.endsWith("/")
25
- ? normalized.slice(0, -1)
26
- : normalized;
27
- const idx = trimmed.lastIndexOf("/");
28
- if (idx < 0) {
29
- return ".";
30
- }
31
- if (idx === 0) {
32
- return "/";
33
- }
34
- return trimmed.slice(0, idx);
35
- },
36
- resolve(...segments) {
37
- if (segments.length === 0) {
38
- return ".";
39
- }
40
- let resolved = "";
41
- for (let i = segments.length - 1; i >= 0; i--) {
42
- const segment = segments[i];
43
- if (!segment) {
44
- continue;
45
- }
46
- if (resolved) {
47
- resolved = `${segment}/${resolved}`;
48
- } else {
49
- resolved = segment;
50
- }
51
- if (path.isAbsolute(segment)) {
52
- break;
53
- }
54
- }
55
- return normalizeResolvedPath(resolved || ".");
56
- },
57
- };
58
-
59
- function normalizeSlashes(filePath: string): string {
60
- return filePath.replace(/\\+/g, "/");
61
- }
62
-
63
- function normalizeResolvedPath(filePath: string): string {
64
- const normalized = normalizeSlashes(filePath);
65
- const isAbsolute = normalized.startsWith("/");
66
- const parts = normalized.split("/");
67
- const stack: string[] = [];
68
- for (const part of parts) {
69
- if (!part || part === ".") {
70
- continue;
71
- }
72
- if (part === "..") {
73
- if (stack.length > 0 && stack[stack.length - 1] !== "..") {
74
- stack.pop();
75
- } else if (!isAbsolute) {
76
- stack.push("..");
77
- }
78
- continue;
79
- }
80
- stack.push(part);
81
- }
82
- if (isAbsolute) {
83
- return `/${stack.join("/")}` || "/";
84
- }
85
- return stack.join("/") || ".";
86
- }
2
+ import path from "path-browserify-esm";
87
3
 
88
4
  export interface GtsConfig extends TranspileOption {}
89
5
 
package/src/index.ts CHANGED
@@ -39,6 +39,4 @@ export {
39
39
  resolveGtsConfig,
40
40
  resolveGtsConfigSync,
41
41
  type GtsConfig,
42
- path,
43
- type PathPolyfill,
44
42
  } from "./config";
@@ -316,7 +316,7 @@ export function gtsPlugin(options: GtsPluginOption = {}) {
316
316
  incDec?: boolean,
317
317
  forInit?: boolean | "await",
318
318
  ): AST.Expression {
319
- if (this.isContextual("query")) {
319
+ if (this.isShortcutContext && this.isContextual("query")) {
320
320
  const expr = this.gts_parseQueryExpression();
321
321
  if (!incDec && this.eat(tokTypes.starstar)) {
322
322
  this.unexpected(this.lastTokStart);
@@ -162,6 +162,15 @@ export const commonGtsVisitor: Visitors<Node, TranspileState> = {
162
162
  value: !!node.star,
163
163
  },
164
164
  },
165
+ {
166
+ type: "Property",
167
+ key: { type: "Identifier", name: "context" },
168
+ computed: false,
169
+ kind: "init",
170
+ method: false,
171
+ shorthand: false,
172
+ value: state.fnArgId,
173
+ }
165
174
  ],
166
175
  },
167
176
  ],