@react-pug/typescript-plugin-react-pug 0.1.9 → 0.1.10

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
@@ -19843,6 +19843,18 @@ function compilePugToTsx(pugText, options = {}) {
19843
19843
  }
19844
19844
  }
19845
19845
 
19846
+ // ../react-pug-core/src/language/tagFunctionPresence.ts
19847
+ function escapeRegex(text) {
19848
+ return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
19849
+ }
19850
+ function createTagFunctionPresenceRegex(tagFunction = "pug") {
19851
+ return new RegExp("(?:^|[^\\w$.])" + escapeRegex(tagFunction) + "\\x60");
19852
+ }
19853
+ function hasTagFunctionCall(sourceText, tagFunction = "pug") {
19854
+ if (!tagFunction) return false;
19855
+ return createTagFunctionPresenceRegex(tagFunction).test(sourceText);
19856
+ }
19857
+
19846
19858
  // ../react-pug-core/src/language/shadowDocument.ts
19847
19859
  var STARTUPJS_OR_CSSXJS_RE = /['"](?:startupjs|cssxjs)['"]/;
19848
19860
  function resolveCompileOptions(originalText, compileOptions) {
@@ -20048,6 +20060,28 @@ function buildImportCleanupWithHelpers(originalText, entry, helpersToAdd, remove
20048
20060
  };
20049
20061
  }
20050
20062
  function buildShadowDocument(originalText, uri, version = 1, tagName = "pug", compileOptions = {}) {
20063
+ if (!hasTagFunctionCall(originalText, tagName)) {
20064
+ return {
20065
+ originalText,
20066
+ uri,
20067
+ regions: [],
20068
+ importCleanups: [],
20069
+ copySegments: [{
20070
+ originalStart: 0,
20071
+ originalEnd: originalText.length,
20072
+ shadowStart: 0,
20073
+ shadowEnd: originalText.length
20074
+ }],
20075
+ mappedRegions: [],
20076
+ insertions: [],
20077
+ shadowText: originalText,
20078
+ version,
20079
+ regionDeltas: [],
20080
+ usesTagFunction: false,
20081
+ hasTagImport: false,
20082
+ missingTagImport: null
20083
+ };
20084
+ }
20051
20085
  const resolvedCompileOptions = resolveCompileOptions(originalText, compileOptions);
20052
20086
  const analysis = extractPugAnalysis(originalText, uri, tagName);
20053
20087
  const regions = analysis.regions;
@@ -20504,6 +20538,14 @@ function init(modules) {
20504
20538
  if (!enabled) return original;
20505
20539
  try {
20506
20540
  const text = original.getText(0, original.getLength());
20541
+ if (!hasTagFunctionCall(text, tagFunction)) {
20542
+ if (docCache.has(fileName)) {
20543
+ docCache.delete(fileName);
20544
+ fileExtraTypesState.delete(fileName);
20545
+ fileClassShorthandState.delete(fileName);
20546
+ }
20547
+ return original;
20548
+ }
20507
20549
  const cached = docCache.get(fileName);
20508
20550
  const extraTypesEnabled = shouldInjectExtraReactAttributes(fileName, text);
20509
20551
  const classOptions = resolveClassShorthandOptions(text);