@react-pug/typescript-plugin-react-pug 0.1.13 → 0.1.16

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/plugin.js CHANGED
@@ -14523,7 +14523,7 @@ var require_lib = __commonJS({
14523
14523
  return getParser(options, input).parse();
14524
14524
  }
14525
14525
  }
14526
- function parseExpression2(input, options) {
14526
+ function parseExpression3(input, options) {
14527
14527
  const parser = getParser(options, input);
14528
14528
  if (parser.options.strictMode) {
14529
14529
  parser.state.strict = true;
@@ -14578,7 +14578,7 @@ var require_lib = __commonJS({
14578
14578
  return cls;
14579
14579
  }
14580
14580
  exports2.parse = parse3;
14581
- exports2.parseExpression = parseExpression2;
14581
+ exports2.parseExpression = parseExpression3;
14582
14582
  exports2.tokTypes = tokTypes;
14583
14583
  }
14584
14584
  });
@@ -14663,7 +14663,7 @@ var require_is_expression = __commonJS({
14663
14663
  var DEFAULT_OPTIONS = {
14664
14664
  throw: false
14665
14665
  };
14666
- function parseExpression2(src) {
14666
+ function parseExpression3(src) {
14667
14667
  babelParser.parseExpression(src, {
14668
14668
  sourceType: "module",
14669
14669
  plugins: ["typescript", "jsx"]
@@ -14672,7 +14672,7 @@ var require_is_expression = __commonJS({
14672
14672
  function isExpression2(src, options) {
14673
14673
  options = objectAssign({}, DEFAULT_OPTIONS, options);
14674
14674
  try {
14675
- parseExpression2(src);
14675
+ parseExpression3(src);
14676
14676
  } catch (error) {
14677
14677
  if (!options.throw) {
14678
14678
  return false;
@@ -39563,6 +39563,9 @@ function extractPugAnalysis(text, filename, tagName = "pug") {
39563
39563
  };
39564
39564
  }
39565
39565
 
39566
+ // ../react-pug-core/src/language/pugToTsx.ts
39567
+ var import_parser2 = __toESM(require_lib());
39568
+
39566
39569
  // ../react-pug-core/src/language/regionOffsetMapping.ts
39567
39570
  function rawToStrippedOffset(rawText, rawOffset, commonIndent) {
39568
39571
  if (commonIndent === 0) return rawOffset;
@@ -39649,6 +39652,16 @@ var TsxEmitter = class {
39649
39652
  return { tsx: this.tsx, mappings: this.mappings };
39650
39653
  }
39651
39654
  };
39655
+ function getStaticStringLiteralValue(expr) {
39656
+ try {
39657
+ const parsed = (0, import_parser2.parseExpression)(expr, {
39658
+ plugins: ["jsx", "decorators-legacy", "typescript"]
39659
+ });
39660
+ return parsed.type === "StringLiteral" ? parsed.value : null;
39661
+ } catch {
39662
+ return null;
39663
+ }
39664
+ }
39652
39665
  function buildTypingRecoveryText(text) {
39653
39666
  const lines = text.split("\n");
39654
39667
  let changed = false;
@@ -40273,7 +40286,7 @@ function emitAttributeValueAsExpression(attr, emitter, pugText) {
40273
40286
  const attrOffset = lineColToOffset(pugText, attr.line, attr.column);
40274
40287
  const valOffset = attrOffset + attr.name.length + 1;
40275
40288
  const val = attr.val;
40276
- if (val.startsWith('"') && val.endsWith('"') || val.startsWith("'") && val.endsWith("'")) {
40289
+ if (getStaticStringLiteralValue(val) != null) {
40277
40290
  emitter.emitMapped(val, valOffset, FULL_FEATURES);
40278
40291
  return;
40279
40292
  }
@@ -40342,18 +40355,11 @@ function emitTag(node, emitter, pugText) {
40342
40355
  for (const attr of node.attrs) {
40343
40356
  if (attr.name === "class" && typeof attr.val === "string") {
40344
40357
  const raw = attr.val;
40345
- if (raw.startsWith("'") && raw.endsWith("'")) {
40346
- const classOffset = lineColToOffset(pugText, attr.line, attr.column);
40347
- classNames.push({
40348
- name: raw.slice(1, -1),
40349
- offset: classOffset,
40350
- sourceLength: Math.max(1, raw.length),
40351
- nameOffset: classOffset + 1
40352
- });
40353
- } else if (raw.startsWith('"') && raw.endsWith('"')) {
40358
+ const staticValue = getStaticStringLiteralValue(raw);
40359
+ if (staticValue != null) {
40354
40360
  const classOffset = lineColToOffset(pugText, attr.line, attr.column);
40355
40361
  classNames.push({
40356
- name: raw.slice(1, -1),
40362
+ name: staticValue,
40357
40363
  offset: classOffset,
40358
40364
  sourceLength: Math.max(1, raw.length),
40359
40365
  nameOffset: classOffset + 1
@@ -40363,10 +40369,9 @@ function emitTag(node, emitter, pugText) {
40363
40369
  }
40364
40370
  } else if (attr.name === "id" && typeof attr.val === "string") {
40365
40371
  const raw = attr.val;
40366
- if (raw.startsWith("'") && raw.endsWith("'")) {
40367
- idValue = raw.slice(1, -1);
40368
- } else if (raw.startsWith('"') && raw.endsWith('"')) {
40369
- idValue = raw.slice(1, -1);
40372
+ const staticValue = getStaticStringLiteralValue(raw);
40373
+ if (staticValue != null) {
40374
+ idValue = staticValue;
40370
40375
  } else {
40371
40376
  regularAttrs.push(attr);
40372
40377
  }
@@ -40459,7 +40464,7 @@ function emitAttribute(attr, emitter, pugText) {
40459
40464
  }
40460
40465
  if (typeof attr.val === "string") {
40461
40466
  const val = attr.val;
40462
- if (val.startsWith('"') && val.endsWith('"') || val.startsWith("'") && val.endsWith("'")) {
40467
+ if (getStaticStringLiteralValue(val) != null) {
40463
40468
  emitter.emitSynthetic("=");
40464
40469
  const valOffset = attrOffset + attr.name.length + 1;
40465
40470
  emitter.emitMapped(val, valOffset, FULL_FEATURES);
@@ -41637,7 +41642,7 @@ var bufLength = 1024 * 16;
41637
41642
 
41638
41643
  // ../react-pug-core/src/language/lintTransform.ts
41639
41644
  var import_generator = __toESM(require_lib8());
41640
- var import_parser2 = __toESM(require_lib());
41645
+ var import_parser3 = __toESM(require_lib());
41641
41646
  var t = __toESM(require_lib7());
41642
41647
 
41643
41648
  // ../react-pug-core/src/language/documentIssues.ts