@gi-tcg/gts-transpiler 0.3.9 → 0.3.11

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 CHANGED
@@ -68,8 +68,8 @@ function loosePlugin() {
68
68
  return function loosePluginTransformer(parser) {
69
69
  return class LooseParser extends parser {
70
70
  _patchedParseIdent = (liberal) => {
71
- if (this.type !== tokTypes.name) return this.createDummyIdentifier();
72
- else return super.parseIdent(liberal);
71
+ if (this.type === tokTypes.name || this.type.keyword) return super.parseIdent(liberal);
72
+ else return this.createDummyIdentifier();
73
73
  };
74
74
  #proxiedThis = new Proxy(this, { get: (target, prop) => {
75
75
  if (prop === "parseIdent") return this._patchedParseIdent;
@@ -1755,6 +1755,11 @@ function getPrintOptions(source, state) {
1755
1755
  context.write("\"");
1756
1756
  context.writeMapped(text.slice(1, -1), node.range[0], node.range[1], LITERAL_FROM_ID_MAPPING_DATA);
1757
1757
  context.write("\"");
1758
+ const generatedEnd = context.generatedOffset;
1759
+ context.createExtraMapping({
1760
+ start: node.range[0],
1761
+ end: node.range[1]
1762
+ }, generatedStart, generatedEnd, VERIFICATION_ONLY_MAPPING_DATA);
1758
1763
  } else if (state.attributeNameNodes.has(node) && node.range) context.writeMapped(node.raw ?? JSON.stringify(node.value), node.range[0], node.range[1], ATTRIBUTE_NAME_MAPPING_DATA);
1759
1764
  else if (directActionStubRange = state.directActionStubRange.get(node)) context.writeMapped(node.raw ?? JSON.stringify(node.value), directActionStubRange.start, directActionStubRange.start + 1, DIRECT_ACTION_STUB_MAPPING_DATA);
1760
1765
  else defaultPrinters.Literal(node, context);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gi-tcg/gts-transpiler",
3
- "version": "0.3.9",
3
+ "version": "0.3.11",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/piovium/gts.git"
@@ -1,7 +1,7 @@
1
1
  import { tokTypes, type Parser } from "acorn";
2
2
  import type { AST, Parse } from "../types.js";
3
3
 
4
- export const DUMMY_PLACEHOLDER = '';
4
+ export const DUMMY_PLACEHOLDER = "";
5
5
 
6
6
  export function loosePlugin() {
7
7
  return function loosePluginTransformer(parser: typeof Parser): typeof Parser {
@@ -9,10 +9,10 @@ export function loosePlugin() {
9
9
  private readonly _patchedParseIdent = (
10
10
  liberal?: boolean,
11
11
  ): AST.Identifier => {
12
- if (this.type !== tokTypes.name) {
13
- return this.createDummyIdentifier();
14
- } else {
12
+ if (this.type === tokTypes.name || this.type.keyword) {
15
13
  return super.parseIdent(liberal);
14
+ } else {
15
+ return this.createDummyIdentifier();
16
16
  }
17
17
  };
18
18
  readonly #proxiedThis = new Proxy(this, {
@@ -29,7 +29,10 @@ export function loosePlugin() {
29
29
  });
30
30
 
31
31
  createDummyIdentifier() {
32
- const dummy = this.startNodeAt(this.lastTokEnd, this.lastTokEndLoc) as AST.Identifier;
32
+ const dummy = this.startNodeAt(
33
+ this.lastTokEnd,
34
+ this.lastTokEndLoc,
35
+ ) as AST.Identifier;
33
36
  dummy.name = DUMMY_PLACEHOLDER;
34
37
  dummy.isDummy = true;
35
38
  return this.finishNode(dummy, "Identifier");
@@ -92,6 +92,17 @@ export function getPrintOptions(
92
92
  LITERAL_FROM_ID_MAPPING_DATA,
93
93
  );
94
94
  context.write('"');
95
+ const generatedEnd = context.generatedOffset;
96
+ // Map error squiggle at quotation mark to the inner content
97
+ context.createExtraMapping(
98
+ {
99
+ start: node.range[0],
100
+ end: node.range[1],
101
+ },
102
+ generatedStart,
103
+ generatedEnd,
104
+ VERIFICATION_ONLY_MAPPING_DATA,
105
+ )
95
106
  } else if (state.attributeNameNodes.has(node) && node.range) {
96
107
  context.writeMapped(
97
108
  node.raw ?? JSON.stringify((node as EspolarAST.Literal).value),