@vue-vine/eslint-parser 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. package/dist/index.js +155 -76
  2. package/dist/index.mjs +154 -75
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -4,14 +4,7 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __getProtoOf = Object.getPrototypeOf;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
8
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
9
- }) : x)(function(x) {
10
- if (typeof require !== "undefined")
11
- return require.apply(this, arguments);
12
- throw Error('Dynamic require of "' + x + '" is not supported');
13
- });
14
- var __commonJS = (cb, mod) => function __require2() {
7
+ var __commonJS = (cb, mod) => function __require() {
15
8
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
16
9
  };
17
10
  var __copyProps = (to, from, except, desc) => {
@@ -2397,22 +2390,31 @@ var _parser = require('@typescript-eslint/parser');
2397
2390
 
2398
2391
  // src/template/utils/process-vine-template-node.ts
2399
2392
  var _typescriptestree = require('@typescript-eslint/typescript-estree');
2400
- function fixVineOffset(token, {
2401
- templateStartOffset,
2402
- templateStartLine,
2403
- templateStartColumn
2404
- }, cache) {
2405
- if (cache.has(token)) {
2406
- return;
2407
- }
2408
- cache.add(token);
2393
+ function fixVineOffset(token, fixCtx) {
2394
+ const {
2395
+ posInfo: {
2396
+ templateStartOffset,
2397
+ templateStartLine,
2398
+ templateStartColumn
2399
+ },
2400
+ fixedCache: cache
2401
+ } = fixCtx;
2409
2402
  if (token.type !== "VTemplateRoot") {
2410
- token.range[0] += templateStartOffset;
2411
- token.loc.start.line += templateStartLine - 1;
2412
- token.loc.start.column = token.loc.start.line === templateStartLine ? templateStartColumn + token.loc.start.column : token.loc.start.column;
2413
- token.loc.end.line += templateStartLine - 1;
2414
- token.loc.end.column = token.loc.end.line === templateStartLine ? templateStartColumn + token.loc.end.column : token.loc.end.column;
2415
- token.range[1] += templateStartOffset;
2403
+ if (!cache.has(token.range)) {
2404
+ token.range[0] += templateStartOffset;
2405
+ token.range[1] += templateStartOffset;
2406
+ cache.add(token.range);
2407
+ }
2408
+ if (!cache.has(token.loc.start)) {
2409
+ token.loc.start.line += templateStartLine - 1;
2410
+ token.loc.start.column = token.loc.start.line === templateStartLine ? templateStartColumn + token.loc.start.column : token.loc.start.column;
2411
+ cache.add(token.loc.start);
2412
+ }
2413
+ if (!cache.has(token.loc.end)) {
2414
+ token.loc.end.line += templateStartLine - 1;
2415
+ token.loc.end.column = token.loc.end.line === templateStartLine ? templateStartColumn + token.loc.end.column : token.loc.end.column;
2416
+ cache.add(token.loc.end);
2417
+ }
2416
2418
  }
2417
2419
  }
2418
2420
  function extractForVineTemplate(ast) {
@@ -2467,13 +2469,13 @@ function extractForVineTemplate(ast) {
2467
2469
  function prepareTemplate(templateNode) {
2468
2470
  const { quasi: { quasis } } = templateNode;
2469
2471
  const templateRawNode = quasis[0];
2472
+ const templateRawContent = templateRawNode.value.raw;
2470
2473
  const templateStartLine = templateRawNode.loc.start.line;
2474
+ const templateEndLine = templateRawNode.loc.end.line;
2471
2475
  const templateStartColumn = templateRawNode.loc.start.column + 1;
2472
2476
  const templateStartOffset = templateRawNode.range[0] + 1;
2473
- const templateEndLine = templateRawNode.loc.end.line;
2474
2477
  const templateEndColumn = templateRawNode.loc.end.column - 1;
2475
2478
  const templateEndOffset = templateRawNode.range[1] - 1;
2476
- const templateRawContent = templateRawNode.value.raw;
2477
2479
  return {
2478
2480
  templatePositionInfo: {
2479
2481
  templateStartLine,
@@ -7716,6 +7718,7 @@ function replaceTokens(templateMeta, node, newTokens) {
7716
7718
  var import_first = __toESM(require_first());
7717
7719
  var import_last2 = __toESM(require_last());
7718
7720
  var import_sortedIndexBy3 = __toESM(require_sortedIndexBy());
7721
+ var _url = require('url');
7719
7722
 
7720
7723
  // src/common/espree.ts
7721
7724
  var _path = require('path'); var _path2 = _interopRequireDefault(_path);
@@ -7726,9 +7729,11 @@ var _semver = require('semver');
7726
7729
  // src/common/linter-require.ts
7727
7730
 
7728
7731
 
7729
- // src/common/create-require.ts
7730
7732
  var _module = require('module'); var _module2 = _interopRequireDefault(_module);
7731
7733
 
7734
+ // src/common/create-require.ts
7735
+
7736
+
7732
7737
  var createRequire = _module2.default.createRequire || _module2.default.createRequireFromPath || ((modname) => {
7733
7738
  const mod = new (0, _module2.default)(modname);
7734
7739
  mod.filename = modname;
@@ -7747,6 +7752,9 @@ function isLinterPath(p) {
7747
7752
  );
7748
7753
  }
7749
7754
  function getLinterRequire() {
7755
+ const __require = _module.createRequire.call(void 0,
7756
+ _url.fileURLToPath.call(void 0, import.meta.url)
7757
+ );
7750
7758
  const linterPath = Object.keys(__require.cache).find(isLinterPath);
7751
7759
  if (linterPath) {
7752
7760
  try {
@@ -7847,6 +7855,25 @@ function getLatestEcmaVersion(espree) {
7847
7855
  }
7848
7856
 
7849
7857
  // src/common/fix-locations.ts
7858
+ function fixVineOffsetForScript(result, vineFixLocationContext) {
7859
+ const traversed = /* @__PURE__ */ new WeakSet();
7860
+ traverseNodes(result.ast, {
7861
+ visitorKeys: result.visitorKeys,
7862
+ enterNode(node) {
7863
+ if (!traversed.has(node)) {
7864
+ fixVineOffset(node, vineFixLocationContext);
7865
+ }
7866
+ },
7867
+ leaveNode() {
7868
+ }
7869
+ });
7870
+ for (const token of result.ast.tokens || []) {
7871
+ fixVineOffset(token, vineFixLocationContext);
7872
+ }
7873
+ for (const comment of result.ast.comments || []) {
7874
+ fixVineOffset(comment, vineFixLocationContext);
7875
+ }
7876
+ }
7850
7877
  function fixLocations(result, locationCalculator) {
7851
7878
  fixNodeLocations(result.ast, result.visitorKeys, locationCalculator);
7852
7879
  for (const token of result.ast.tokens || []) {
@@ -8266,10 +8293,14 @@ function throwErrorAsAdjustingOutsideOfCode(err, code, locationCalculator) {
8266
8293
  }
8267
8294
  throw err;
8268
8295
  }
8269
- function parseScriptFragment(code, locationCalculator, parserOptions) {
8296
+ function parseScriptFragment(code, locationCalculator, vineFixLocationContext, parserOptions) {
8270
8297
  try {
8271
- const result = parseScript(code, parserOptions);
8298
+ const result = parseScript(
8299
+ code,
8300
+ parserOptions
8301
+ );
8272
8302
  fixLocations(result, locationCalculator);
8303
+ fixVineOffsetForScript(result, vineFixLocationContext);
8273
8304
  return result;
8274
8305
  } catch (err) {
8275
8306
  const perr = ParseError.normalize(err);
@@ -8363,12 +8394,13 @@ function splitFilters(exp) {
8363
8394
  result.push(exp.slice(lastFilterIndex));
8364
8395
  return result;
8365
8396
  }
8366
- function parseExpressionBody(code, locationCalculator, parserOptions, allowEmpty = false) {
8397
+ function parseExpressionBody(code, locationCalculator, vineFixLocationContext, parserOptions, allowEmpty = false) {
8367
8398
  debug('[script] parse expression: "0(%s)"', code);
8368
8399
  try {
8369
8400
  const result = parseScriptFragment(
8370
8401
  `0(${code})`,
8371
8402
  locationCalculator.getSubCalculatorShift(-2),
8403
+ vineFixLocationContext,
8372
8404
  parserOptions
8373
8405
  );
8374
8406
  const { ast } = result;
@@ -8394,12 +8426,13 @@ function parseExpressionBody(code, locationCalculator, parserOptions, allowEmpty
8394
8426
  tokens.shift();
8395
8427
  tokens.shift();
8396
8428
  tokens.pop();
8429
+ fixVineOffset(expression, vineFixLocationContext);
8397
8430
  return { expression, tokens, comments, references, variables: [] };
8398
8431
  } catch (err) {
8399
8432
  return throwErrorAsAdjustingOutsideOfCode(err, code, locationCalculator);
8400
8433
  }
8401
8434
  }
8402
- function parseFilter(code, locationCalculator, parserOptions) {
8435
+ function parseFilter(code, locationCalculator, vineFixLocationContext, parserOptions) {
8403
8436
  debug('[script] parse filter: "%s"', code);
8404
8437
  try {
8405
8438
  const expression = {
@@ -8424,6 +8457,7 @@ function parseFilter(code, locationCalculator, parserOptions) {
8424
8457
  const { ast } = parseScriptFragment(
8425
8458
  `"${calleeCode.trim()}"`,
8426
8459
  subCalculator,
8460
+ vineFixLocationContext,
8427
8461
  parserOptions
8428
8462
  );
8429
8463
  const statement = ast.body[0];
@@ -8467,6 +8501,7 @@ function parseFilter(code, locationCalculator, parserOptions) {
8467
8501
  const result = parseScriptFragment(
8468
8502
  `0${argsCode}`,
8469
8503
  locationCalculator.getSubCalculatorAfter(paren).getSubCalculatorShift(-1),
8504
+ vineFixLocationContext,
8470
8505
  parserOptions
8471
8506
  );
8472
8507
  const { ast } = result;
@@ -8508,6 +8543,9 @@ function parseFilter(code, locationCalculator, parserOptions) {
8508
8543
  }
8509
8544
  function loadParser(parser) {
8510
8545
  if (parser !== "espree") {
8546
+ const __require = createRequire(
8547
+ _url.fileURLToPath.call(void 0, import.meta.url)
8548
+ );
8511
8549
  return __require(parser);
8512
8550
  }
8513
8551
  return getEspreeFromUser();
@@ -8520,13 +8558,14 @@ function parseScript(code, parserOptions) {
8520
8558
  }
8521
8559
  return { ast: result };
8522
8560
  }
8523
- function parseExpression(code, locationCalculator, parserOptions, { allowEmpty = false, allowFilters = false } = {}) {
8561
+ function parseExpression(code, locationCalculator, vineFixLocationContext, parserOptions, { allowEmpty = false, allowFilters = false } = {}) {
8524
8562
  debug('[script] parse expression: "%s"', code);
8525
8563
  const [mainCode, ...filterCodes] = allowFilters ? splitFilters(code) : [code];
8526
8564
  if (filterCodes.length === 0) {
8527
8565
  return parseExpressionBody(
8528
8566
  code,
8529
8567
  locationCalculator,
8568
+ vineFixLocationContext,
8530
8569
  parserOptions,
8531
8570
  allowEmpty
8532
8571
  );
@@ -8534,6 +8573,7 @@ function parseExpression(code, locationCalculator, parserOptions, { allowEmpty =
8534
8573
  const retB = parseExpressionBody(
8535
8574
  mainCode,
8536
8575
  locationCalculator,
8576
+ vineFixLocationContext,
8537
8577
  parserOptions
8538
8578
  );
8539
8579
  if (!retB.expression) {
@@ -8565,6 +8605,7 @@ function parseExpression(code, locationCalculator, parserOptions, { allowEmpty =
8565
8605
  const retF = parseFilter(
8566
8606
  filterCode,
8567
8607
  locationCalculator.getSubCalculatorShift(prevLoc + 1),
8608
+ vineFixLocationContext,
8568
8609
  parserOptions
8569
8610
  );
8570
8611
  if (retF) {
@@ -8583,7 +8624,7 @@ function parseExpression(code, locationCalculator, parserOptions, { allowEmpty =
8583
8624
  ret.expression.loc.end = lastToken.loc.end;
8584
8625
  return ret;
8585
8626
  }
8586
- function parseVForExpression(code, locationCalculator, parserOptions) {
8627
+ function parseVForExpression(code, locationCalculator, vineFixLocationContext, parserOptions) {
8587
8628
  if (code.trim() === "") {
8588
8629
  throwEmptyError(locationCalculator, "'<alias> in <expression>'");
8589
8630
  }
@@ -8591,6 +8632,7 @@ function parseVForExpression(code, locationCalculator, parserOptions) {
8591
8632
  return parseVForExpressionForEcmaVersion5(
8592
8633
  code,
8593
8634
  locationCalculator,
8635
+ vineFixLocationContext,
8594
8636
  parserOptions
8595
8637
  );
8596
8638
  }
@@ -8610,6 +8652,7 @@ function parseVForExpression(code, locationCalculator, parserOptions) {
8610
8652
  locationCalculator.getSubCalculatorShift(
8611
8653
  processed.hasParens ? -8 : -9
8612
8654
  ),
8655
+ vineFixLocationContext,
8613
8656
  parserOptions
8614
8657
  );
8615
8658
  const { ast } = result;
@@ -8666,6 +8709,7 @@ function parseVForExpression(code, locationCalculator, parserOptions) {
8666
8709
  }
8667
8710
  }
8668
8711
  right.parent = expression;
8712
+ fixVineOffset(expression, vineFixLocationContext);
8669
8713
  return { expression, tokens, comments, references, variables };
8670
8714
  } catch (err) {
8671
8715
  return throwErrorAsAdjustingOutsideOfCode(err, code, locationCalculator);
@@ -8675,7 +8719,7 @@ function isEcmaVersion5(parserOptions) {
8675
8719
  const ecmaVersion = getEcmaVersionIfUseEspree(parserOptions);
8676
8720
  return ecmaVersion != null && ecmaVersion <= 5;
8677
8721
  }
8678
- function parseVForExpressionForEcmaVersion5(code, locationCalculator, parserOptions) {
8722
+ function parseVForExpressionForEcmaVersion5(code, locationCalculator, vineFixLocationContext, parserOptions) {
8679
8723
  const processed = processVForAliasAndIterator(code);
8680
8724
  if (!processed.aliases.trim()) {
8681
8725
  return throwEmptyError(locationCalculator, "an alias");
@@ -8688,6 +8732,7 @@ function parseVForExpressionForEcmaVersion5(code, locationCalculator, parserOpti
8688
8732
  locationCalculator.getSubCalculatorShift(
8689
8733
  processed.hasParens ? 0 : -1
8690
8734
  ),
8735
+ vineFixLocationContext,
8691
8736
  parserOptions
8692
8737
  );
8693
8738
  if (processed.hasParens) {
@@ -8727,6 +8772,7 @@ function parseVForExpressionForEcmaVersion5(code, locationCalculator, parserOpti
8727
8772
  const parsedIterator = parseVForIteratorForEcmaVersion5(
8728
8773
  processed.iterator,
8729
8774
  locationCalculator.getSubCalculatorShift(delimiterEnd),
8775
+ vineFixLocationContext,
8730
8776
  parserOptions
8731
8777
  );
8732
8778
  tokens.push(...parsedIterator.tokens);
@@ -8753,10 +8799,11 @@ function parseVForExpressionForEcmaVersion5(code, locationCalculator, parserOpti
8753
8799
  return throwErrorAsAdjustingOutsideOfCode(err, code, locationCalculator);
8754
8800
  }
8755
8801
  }
8756
- function parseVForAliasesForEcmaVersion5(code, locationCalculator, parserOptions) {
8802
+ function parseVForAliasesForEcmaVersion5(code, locationCalculator, vineFixLocationContext, parserOptions) {
8757
8803
  const result = parseScriptFragment(
8758
8804
  `0(${code})`,
8759
8805
  locationCalculator.getSubCalculatorShift(-2),
8806
+ vineFixLocationContext,
8760
8807
  parserOptions
8761
8808
  );
8762
8809
  const { ast } = result;
@@ -8793,10 +8840,11 @@ function parseVForAliasesForEcmaVersion5(code, locationCalculator, parserOptions
8793
8840
  return ret;
8794
8841
  }
8795
8842
  }
8796
- function parseVForIteratorForEcmaVersion5(code, locationCalculator, parserOptions) {
8843
+ function parseVForIteratorForEcmaVersion5(code, locationCalculator, vineFixLocationContext, parserOptions) {
8797
8844
  const result = parseScriptFragment(
8798
8845
  `0(${code})`,
8799
8846
  locationCalculator.getSubCalculatorShift(-2),
8847
+ vineFixLocationContext,
8800
8848
  parserOptions
8801
8849
  );
8802
8850
  const { ast } = result;
@@ -8818,13 +8866,23 @@ function parseVForIteratorForEcmaVersion5(code, locationCalculator, parserOption
8818
8866
  tokens.pop();
8819
8867
  return { right, tokens, comments, references };
8820
8868
  }
8821
- function parseVOnExpression(code, locationCalculator, parserOptions) {
8869
+ function parseVOnExpression(code, locationCalculator, vineFixLocationContext, parserOptions) {
8822
8870
  if (IS_FUNCTION_EXPRESSION.test(code) || IS_SIMPLE_PATH.test(code)) {
8823
- return parseExpressionBody(code, locationCalculator, parserOptions);
8871
+ return parseExpressionBody(
8872
+ code,
8873
+ locationCalculator,
8874
+ vineFixLocationContext,
8875
+ parserOptions
8876
+ );
8824
8877
  }
8825
- return parseVOnExpressionBody(code, locationCalculator, parserOptions);
8878
+ return parseVOnExpressionBody(
8879
+ code,
8880
+ locationCalculator,
8881
+ vineFixLocationContext,
8882
+ parserOptions
8883
+ );
8826
8884
  }
8827
- function parseVOnExpressionBody(code, locationCalculator, parserOptions) {
8885
+ function parseVOnExpressionBody(code, locationCalculator, vineFixLocationContext, parserOptions) {
8828
8886
  debug('[script] parse v-on expression: "void function($event){%s}"', code);
8829
8887
  if (code.trim() === "") {
8830
8888
  throwEmptyError(locationCalculator, "statements");
@@ -8833,6 +8891,7 @@ function parseVOnExpressionBody(code, locationCalculator, parserOptions) {
8833
8891
  const result = parseScriptFragment(
8834
8892
  `void function($event){${code}}`,
8835
8893
  locationCalculator.getSubCalculatorShift(-22),
8894
+ vineFixLocationContext,
8836
8895
  parserOptions
8837
8896
  );
8838
8897
  const { ast } = result;
@@ -8863,12 +8922,13 @@ function parseVOnExpressionBody(code, locationCalculator, parserOptions) {
8863
8922
  }
8864
8923
  tokens.splice(0, 6);
8865
8924
  tokens.pop();
8925
+ fixVineOffset(expression, vineFixLocationContext);
8866
8926
  return { expression, tokens, comments, references, variables: [] };
8867
8927
  } catch (err) {
8868
8928
  return throwErrorAsAdjustingOutsideOfCode(err, code, locationCalculator);
8869
8929
  }
8870
8930
  }
8871
- function parseSlotScopeExpression(code, locationCalculator, parserOptions) {
8931
+ function parseSlotScopeExpression(code, locationCalculator, vineFixLocationContext, parserOptions) {
8872
8932
  debug('[script] parse slot-scope expression: "void function(%s) {}"', code);
8873
8933
  if (code.trim() === "") {
8874
8934
  throwEmptyError(
@@ -8880,6 +8940,7 @@ function parseSlotScopeExpression(code, locationCalculator, parserOptions) {
8880
8940
  const result = parseScriptFragment(
8881
8941
  `void function(${code}) {}`,
8882
8942
  locationCalculator.getSubCalculatorShift(-14),
8943
+ vineFixLocationContext,
8883
8944
  parserOptions
8884
8945
  );
8885
8946
  const { ast } = result;
@@ -8952,7 +9013,7 @@ function getStandardDirectiveKind(element, directiveKey) {
8952
9013
  }
8953
9014
  return null;
8954
9015
  }
8955
- function parseAttributeValue(code, parserOptions, globalLocationCalculator, node, element, directiveKey) {
9016
+ function parseAttributeValue(code, parserOptions, globalLocationCalculator, vineFixLocationContext, node, element, directiveKey) {
8956
9017
  const firstChar = code[node.range[0]];
8957
9018
  const quoted = firstChar === '"' || firstChar === "'";
8958
9019
  const locationCalculator = globalLocationCalculator.getSubCalculatorAfter(
@@ -8975,29 +9036,38 @@ function parseAttributeValue(code, parserOptions, globalLocationCalculator, node
8975
9036
  result = parseVForExpression(
8976
9037
  node.value,
8977
9038
  locationCalculator,
9039
+ vineFixLocationContext,
8978
9040
  parserOptions
8979
9041
  );
8980
9042
  } else if (directiveKind === "on" && directiveKey.argument != null) {
8981
9043
  result = parseVOnExpression(
8982
9044
  node.value,
8983
9045
  locationCalculator,
9046
+ vineFixLocationContext,
8984
9047
  parserOptions
8985
9048
  );
8986
9049
  } else if (directiveKind === "slot") {
8987
9050
  result = parseSlotScopeExpression(
8988
9051
  node.value,
8989
9052
  locationCalculator,
9053
+ vineFixLocationContext,
8990
9054
  parserOptions
8991
9055
  );
8992
9056
  } else if (directiveKind === "bind") {
8993
9057
  result = parseExpression(
8994
9058
  node.value,
8995
9059
  locationCalculator,
9060
+ vineFixLocationContext,
8996
9061
  parserOptions,
8997
9062
  { allowFilters: true }
8998
9063
  );
8999
9064
  } else {
9000
- result = parseExpression(node.value, locationCalculator, parserOptions);
9065
+ result = parseExpression(
9066
+ node.value,
9067
+ locationCalculator,
9068
+ vineFixLocationContext,
9069
+ parserOptions
9070
+ );
9001
9071
  }
9002
9072
  if (quoted) {
9003
9073
  result.tokens.unshift(
@@ -9021,7 +9091,7 @@ function parseAttributeValue(code, parserOptions, globalLocationCalculator, node
9021
9091
  }
9022
9092
  return result;
9023
9093
  }
9024
- function parseDirectiveKeyStatically(node, templateMeta) {
9094
+ function parseDirectiveKeyStatically(node, templateMeta, vineFixLocationContext) {
9025
9095
  const {
9026
9096
  name: text,
9027
9097
  rawName: rawText,
@@ -9039,9 +9109,10 @@ function parseDirectiveKeyStatically(node, templateMeta) {
9039
9109
  argument: null,
9040
9110
  modifiers: []
9041
9111
  };
9112
+ fixVineOffset(directiveKey, vineFixLocationContext);
9042
9113
  let i = 0;
9043
- function createIdentifier(start, end, name) {
9044
- return {
9114
+ function createIdentifier(vineFixLocationContext2, start, end, name) {
9115
+ const id = {
9045
9116
  type: "VIdentifier",
9046
9117
  parent: directiveKey,
9047
9118
  range: [offset + start, offset + end],
@@ -9052,27 +9123,29 @@ function parseDirectiveKeyStatically(node, templateMeta) {
9052
9123
  name: name || text.slice(start, end),
9053
9124
  rawName: rawText.slice(start, end)
9054
9125
  };
9126
+ fixVineOffset(id, vineFixLocationContext2);
9127
+ return id;
9055
9128
  }
9056
9129
  if (shorthandSign.test(text)) {
9057
9130
  const sign = text[0];
9058
- directiveKey.name = createIdentifier(0, 1, shorthandNameMap[sign]);
9131
+ directiveKey.name = createIdentifier(vineFixLocationContext, 0, 1, shorthandNameMap[sign]);
9059
9132
  i = 1;
9060
9133
  } else {
9061
9134
  const colon = text.indexOf(":");
9062
9135
  if (colon !== -1) {
9063
- directiveKey.name = createIdentifier(0, colon);
9136
+ directiveKey.name = createIdentifier(vineFixLocationContext, 0, colon);
9064
9137
  i = colon + 1;
9065
9138
  }
9066
9139
  }
9067
9140
  if (directiveKey.name != null && text[i] === "[") {
9068
9141
  const len = text.slice(i).lastIndexOf("]");
9069
9142
  if (len !== -1) {
9070
- directiveKey.argument = createIdentifier(i, i + len + 1);
9143
+ directiveKey.argument = createIdentifier(vineFixLocationContext, i, i + len + 1);
9071
9144
  i = i + len + 1 + (text[i + len + 1] === "." ? 1 : 0);
9072
9145
  }
9073
9146
  }
9074
9147
  const modifiers = text.slice(i).split(".").map((modifierName) => {
9075
- const modifier = createIdentifier(i, i + modifierName.length);
9148
+ const modifier = createIdentifier(vineFixLocationContext, i, i + modifierName.length);
9076
9149
  if (modifierName === "" && i < text.length) {
9077
9150
  insertError(
9078
9151
  templateMeta,
@@ -9108,7 +9181,7 @@ function parseDirectiveKeyStatically(node, templateMeta) {
9108
9181
  }
9109
9182
  if (directiveKey.name.rawName === "." && !directiveKey.modifiers.some(isPropModifier)) {
9110
9183
  const pos = (directiveKey.argument || directiveKey.name).range[1] - offset;
9111
- const propModifier = createIdentifier(pos, pos, "prop");
9184
+ const propModifier = createIdentifier(vineFixLocationContext, pos, pos, "prop");
9112
9185
  directiveKey.modifiers.unshift(propModifier);
9113
9186
  }
9114
9187
  return directiveKey;
@@ -9171,7 +9244,7 @@ function parseDirectiveKeyTokens(node) {
9171
9244
  }
9172
9245
  return tokens;
9173
9246
  }
9174
- function convertDynamicArgument(node, templateMeta, parserOptions, locationCalculator) {
9247
+ function convertDynamicArgument(node, templateMeta, parserOptions, locationCalculator, vineFixLocationContext) {
9175
9248
  const { argument } = node;
9176
9249
  if (!(argument != null && argument.type === "VIdentifier" && argument.name.startsWith("[") && argument.name.endsWith("]"))) {
9177
9250
  return;
@@ -9181,6 +9254,7 @@ function convertDynamicArgument(node, templateMeta, parserOptions, locationCalcu
9181
9254
  const { comments, expression, references, tokens } = parseExpression(
9182
9255
  rawName.slice(1, -1),
9183
9256
  locationCalculator.getSubCalculatorAfter(range[0] + 1),
9257
+ vineFixLocationContext,
9184
9258
  parserOptions
9185
9259
  );
9186
9260
  node.argument = {
@@ -9191,6 +9265,7 @@ function convertDynamicArgument(node, templateMeta, parserOptions, locationCalcu
9191
9265
  expression,
9192
9266
  references
9193
9267
  };
9268
+ fixVineOffset(node.argument, vineFixLocationContext);
9194
9269
  if (expression != null) {
9195
9270
  expression.parent = node.argument;
9196
9271
  }
@@ -9231,8 +9306,8 @@ function convertDynamicArgument(node, templateMeta, parserOptions, locationCalcu
9231
9306
  }
9232
9307
  }
9233
9308
  }
9234
- function createDirectiveKey(node, templateMeta, parserOptions, locationCalculator) {
9235
- const directiveKey = parseDirectiveKeyStatically(node, templateMeta);
9309
+ function createDirectiveKey(node, templateMeta, parserOptions, locationCalculator, vineFixLocationContext) {
9310
+ const directiveKey = parseDirectiveKeyStatically(node, templateMeta, vineFixLocationContext);
9236
9311
  const tokens = parseDirectiveKeyTokens(directiveKey);
9237
9312
  replaceTokens(templateMeta, directiveKey, tokens);
9238
9313
  if (directiveKey.name.name.startsWith("v-")) {
@@ -9245,11 +9320,12 @@ function createDirectiveKey(node, templateMeta, parserOptions, locationCalculato
9245
9320
  directiveKey,
9246
9321
  templateMeta,
9247
9322
  parserOptions,
9248
- locationCalculator
9323
+ locationCalculator,
9324
+ vineFixLocationContext
9249
9325
  );
9250
9326
  return directiveKey;
9251
9327
  }
9252
- function convertToDirective(node, code, templateMeta, locationCalculator, parserOptions) {
9328
+ function convertToDirective(node, code, templateMeta, locationCalculator, vineFixLocationContext, parserOptions) {
9253
9329
  debug(
9254
9330
  '[template] convert to directive: %s="%s" %j',
9255
9331
  node.key.name,
@@ -9262,7 +9338,12 @@ function convertToDirective(node, code, templateMeta, locationCalculator, parser
9262
9338
  node.key,
9263
9339
  templateMeta,
9264
9340
  parserOptions,
9265
- locationCalculator
9341
+ locationCalculator,
9342
+ vineFixLocationContext
9343
+ );
9344
+ fixVineOffset(
9345
+ directive.key,
9346
+ vineFixLocationContext
9266
9347
  );
9267
9348
  const { argument } = directive.key;
9268
9349
  if (argument && argument.type === "VIdentifier" && argument.name.startsWith("[")) {
@@ -9289,6 +9370,7 @@ function convertToDirective(node, code, templateMeta, locationCalculator, parser
9289
9370
  code,
9290
9371
  parserOptions,
9291
9372
  locationCalculator,
9373
+ vineFixLocationContext,
9292
9374
  node.value,
9293
9375
  node.parent.parent,
9294
9376
  directive.key
@@ -9301,6 +9383,10 @@ function convertToDirective(node, code, templateMeta, locationCalculator, parser
9301
9383
  expression: ret.expression,
9302
9384
  references: ret.references
9303
9385
  };
9386
+ fixVineOffset(
9387
+ directive.value,
9388
+ vineFixLocationContext
9389
+ );
9304
9390
  if (ret.expression != null) {
9305
9391
  ret.expression.parent = directive.value;
9306
9392
  }
@@ -9326,7 +9412,7 @@ function convertToDirective(node, code, templateMeta, locationCalculator, parser
9326
9412
  }
9327
9413
  }
9328
9414
  }
9329
- function processMustache(parserOptions, globalLocationCalculator, templateMeta, node, mustache) {
9415
+ function processMustache(parserOptions, globalLocationCalculator, vineFixLocationContext, templateMeta, node, mustache) {
9330
9416
  const range = [
9331
9417
  mustache.startToken.range[1],
9332
9418
  mustache.endToken.range[0]
@@ -9337,6 +9423,7 @@ function processMustache(parserOptions, globalLocationCalculator, templateMeta,
9337
9423
  const ret = parseExpression(
9338
9424
  mustache.value,
9339
9425
  locationCalculator,
9426
+ vineFixLocationContext,
9340
9427
  parserOptions,
9341
9428
  { allowEmpty: true, allowFilters: true }
9342
9429
  );
@@ -9538,31 +9625,22 @@ var VineTemplateParser = (_class2 = class {
9538
9625
  };
9539
9626
  this.expressionEnabled = true;
9540
9627
  }
9628
+ get fixVineOffsetCtx() {
9629
+ return {
9630
+ posInfo: this.templatePos,
9631
+ fixedCache: this.offsetFixedTokenSet
9632
+ };
9633
+ }
9541
9634
  correctMetaTokenPos() {
9542
9635
  this.vTemplateMeta.tokens.forEach((token) => fixVineOffset(
9543
9636
  token,
9544
- this.templatePos,
9545
- this.offsetFixedTokenSet
9637
+ this.fixVineOffsetCtx
9546
9638
  ));
9547
9639
  this.vTemplateMeta.comments.forEach((comment) => fixVineOffset(
9548
9640
  comment,
9549
- this.templatePos,
9550
- this.offsetFixedTokenSet
9641
+ this.fixVineOffsetCtx
9551
9642
  ));
9552
- fixVineOffset(this.vTemplateRoot, this.templatePos, this.offsetFixedTokenSet);
9553
- }
9554
- correctESTreeTokenPos() {
9555
- traverseNodes(this.vTemplateRoot, {
9556
- enterNode: (node) => {
9557
- fixVineOffset(
9558
- node,
9559
- this.templatePos,
9560
- this.offsetFixedTokenSet
9561
- );
9562
- },
9563
- leaveNode: () => {
9564
- }
9565
- });
9643
+ fixVineOffset(this.vTemplateRoot, this.fixVineOffsetCtx);
9566
9644
  }
9567
9645
  /**
9568
9646
  * Get the current node.
@@ -9692,6 +9770,7 @@ var VineTemplateParser = (_class2 = class {
9692
9770
  this.text,
9693
9771
  this.vTemplateMeta,
9694
9772
  this.locationCalculator,
9773
+ this.fixVineOffsetCtx,
9695
9774
  parserOptions
9696
9775
  );
9697
9776
  }
@@ -9877,6 +9956,7 @@ var VineTemplateParser = (_class2 = class {
9877
9956
  processMustache(
9878
9957
  parserOptions,
9879
9958
  this.locationCalculator,
9959
+ this.fixVineOffsetCtx,
9880
9960
  this.vTemplateMeta,
9881
9961
  container,
9882
9962
  token
@@ -9905,7 +9985,6 @@ var VineTemplateParser = (_class2 = class {
9905
9985
  }
9906
9986
  this.postProcessForScript = [];
9907
9987
  this.correctMetaTokenPos();
9908
- this.correctESTreeTokenPos();
9909
9988
  return [templateRoot, templateMeta];
9910
9989
  }
9911
9990
  }, _class2);
package/dist/index.mjs CHANGED
@@ -4,14 +4,7 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __getProtoOf = Object.getPrototypeOf;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
8
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
9
- }) : x)(function(x) {
10
- if (typeof require !== "undefined")
11
- return require.apply(this, arguments);
12
- throw Error('Dynamic require of "' + x + '" is not supported');
13
- });
14
- var __commonJS = (cb, mod) => function __require2() {
7
+ var __commonJS = (cb, mod) => function __require() {
15
8
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
16
9
  };
17
10
  var __copyProps = (to, from, except, desc) => {
@@ -2397,22 +2390,31 @@ import { parseForESLint as tsParseForESLint } from "@typescript-eslint/parser";
2397
2390
 
2398
2391
  // src/template/utils/process-vine-template-node.ts
2399
2392
  import { TSESTree, simpleTraverse as traverse } from "@typescript-eslint/typescript-estree";
2400
- function fixVineOffset(token, {
2401
- templateStartOffset,
2402
- templateStartLine,
2403
- templateStartColumn
2404
- }, cache) {
2405
- if (cache.has(token)) {
2406
- return;
2407
- }
2408
- cache.add(token);
2393
+ function fixVineOffset(token, fixCtx) {
2394
+ const {
2395
+ posInfo: {
2396
+ templateStartOffset,
2397
+ templateStartLine,
2398
+ templateStartColumn
2399
+ },
2400
+ fixedCache: cache
2401
+ } = fixCtx;
2409
2402
  if (token.type !== "VTemplateRoot") {
2410
- token.range[0] += templateStartOffset;
2411
- token.loc.start.line += templateStartLine - 1;
2412
- token.loc.start.column = token.loc.start.line === templateStartLine ? templateStartColumn + token.loc.start.column : token.loc.start.column;
2413
- token.loc.end.line += templateStartLine - 1;
2414
- token.loc.end.column = token.loc.end.line === templateStartLine ? templateStartColumn + token.loc.end.column : token.loc.end.column;
2415
- token.range[1] += templateStartOffset;
2403
+ if (!cache.has(token.range)) {
2404
+ token.range[0] += templateStartOffset;
2405
+ token.range[1] += templateStartOffset;
2406
+ cache.add(token.range);
2407
+ }
2408
+ if (!cache.has(token.loc.start)) {
2409
+ token.loc.start.line += templateStartLine - 1;
2410
+ token.loc.start.column = token.loc.start.line === templateStartLine ? templateStartColumn + token.loc.start.column : token.loc.start.column;
2411
+ cache.add(token.loc.start);
2412
+ }
2413
+ if (!cache.has(token.loc.end)) {
2414
+ token.loc.end.line += templateStartLine - 1;
2415
+ token.loc.end.column = token.loc.end.line === templateStartLine ? templateStartColumn + token.loc.end.column : token.loc.end.column;
2416
+ cache.add(token.loc.end);
2417
+ }
2416
2418
  }
2417
2419
  }
2418
2420
  function extractForVineTemplate(ast) {
@@ -2467,13 +2469,13 @@ function extractForVineTemplate(ast) {
2467
2469
  function prepareTemplate(templateNode) {
2468
2470
  const { quasi: { quasis } } = templateNode;
2469
2471
  const templateRawNode = quasis[0];
2472
+ const templateRawContent = templateRawNode.value.raw;
2470
2473
  const templateStartLine = templateRawNode.loc.start.line;
2474
+ const templateEndLine = templateRawNode.loc.end.line;
2471
2475
  const templateStartColumn = templateRawNode.loc.start.column + 1;
2472
2476
  const templateStartOffset = templateRawNode.range[0] + 1;
2473
- const templateEndLine = templateRawNode.loc.end.line;
2474
2477
  const templateEndColumn = templateRawNode.loc.end.column - 1;
2475
2478
  const templateEndOffset = templateRawNode.range[1] - 1;
2476
- const templateRawContent = templateRawNode.value.raw;
2477
2479
  return {
2478
2480
  templatePositionInfo: {
2479
2481
  templateStartLine,
@@ -7716,6 +7718,7 @@ function replaceTokens(templateMeta, node, newTokens) {
7716
7718
  var import_first = __toESM(require_first());
7717
7719
  var import_last2 = __toESM(require_last());
7718
7720
  var import_sortedIndexBy3 = __toESM(require_sortedIndexBy());
7721
+ import { fileURLToPath as fileURLToPath2 } from "node:url";
7719
7722
 
7720
7723
  // src/common/espree.ts
7721
7724
  import path3 from "node:path";
@@ -7725,6 +7728,8 @@ import { lt, lte } from "semver";
7725
7728
 
7726
7729
  // src/common/linter-require.ts
7727
7730
  import path2 from "node:path";
7731
+ import { fileURLToPath } from "node:url";
7732
+ import { createRequire as NodeCreateRequire } from "node:module";
7728
7733
 
7729
7734
  // src/common/create-require.ts
7730
7735
  import Module from "node:module";
@@ -7747,6 +7752,9 @@ function isLinterPath(p) {
7747
7752
  );
7748
7753
  }
7749
7754
  function getLinterRequire() {
7755
+ const __require = NodeCreateRequire(
7756
+ fileURLToPath(import.meta.url)
7757
+ );
7750
7758
  const linterPath = Object.keys(__require.cache).find(isLinterPath);
7751
7759
  if (linterPath) {
7752
7760
  try {
@@ -7847,6 +7855,25 @@ function getLatestEcmaVersion(espree) {
7847
7855
  }
7848
7856
 
7849
7857
  // src/common/fix-locations.ts
7858
+ function fixVineOffsetForScript(result, vineFixLocationContext) {
7859
+ const traversed = /* @__PURE__ */ new WeakSet();
7860
+ traverseNodes(result.ast, {
7861
+ visitorKeys: result.visitorKeys,
7862
+ enterNode(node) {
7863
+ if (!traversed.has(node)) {
7864
+ fixVineOffset(node, vineFixLocationContext);
7865
+ }
7866
+ },
7867
+ leaveNode() {
7868
+ }
7869
+ });
7870
+ for (const token of result.ast.tokens || []) {
7871
+ fixVineOffset(token, vineFixLocationContext);
7872
+ }
7873
+ for (const comment of result.ast.comments || []) {
7874
+ fixVineOffset(comment, vineFixLocationContext);
7875
+ }
7876
+ }
7850
7877
  function fixLocations(result, locationCalculator) {
7851
7878
  fixNodeLocations(result.ast, result.visitorKeys, locationCalculator);
7852
7879
  for (const token of result.ast.tokens || []) {
@@ -8266,10 +8293,14 @@ function throwErrorAsAdjustingOutsideOfCode(err, code, locationCalculator) {
8266
8293
  }
8267
8294
  throw err;
8268
8295
  }
8269
- function parseScriptFragment(code, locationCalculator, parserOptions) {
8296
+ function parseScriptFragment(code, locationCalculator, vineFixLocationContext, parserOptions) {
8270
8297
  try {
8271
- const result = parseScript(code, parserOptions);
8298
+ const result = parseScript(
8299
+ code,
8300
+ parserOptions
8301
+ );
8272
8302
  fixLocations(result, locationCalculator);
8303
+ fixVineOffsetForScript(result, vineFixLocationContext);
8273
8304
  return result;
8274
8305
  } catch (err) {
8275
8306
  const perr = ParseError.normalize(err);
@@ -8363,12 +8394,13 @@ function splitFilters(exp) {
8363
8394
  result.push(exp.slice(lastFilterIndex));
8364
8395
  return result;
8365
8396
  }
8366
- function parseExpressionBody(code, locationCalculator, parserOptions, allowEmpty = false) {
8397
+ function parseExpressionBody(code, locationCalculator, vineFixLocationContext, parserOptions, allowEmpty = false) {
8367
8398
  debug('[script] parse expression: "0(%s)"', code);
8368
8399
  try {
8369
8400
  const result = parseScriptFragment(
8370
8401
  `0(${code})`,
8371
8402
  locationCalculator.getSubCalculatorShift(-2),
8403
+ vineFixLocationContext,
8372
8404
  parserOptions
8373
8405
  );
8374
8406
  const { ast } = result;
@@ -8394,12 +8426,13 @@ function parseExpressionBody(code, locationCalculator, parserOptions, allowEmpty
8394
8426
  tokens.shift();
8395
8427
  tokens.shift();
8396
8428
  tokens.pop();
8429
+ fixVineOffset(expression, vineFixLocationContext);
8397
8430
  return { expression, tokens, comments, references, variables: [] };
8398
8431
  } catch (err) {
8399
8432
  return throwErrorAsAdjustingOutsideOfCode(err, code, locationCalculator);
8400
8433
  }
8401
8434
  }
8402
- function parseFilter(code, locationCalculator, parserOptions) {
8435
+ function parseFilter(code, locationCalculator, vineFixLocationContext, parserOptions) {
8403
8436
  debug('[script] parse filter: "%s"', code);
8404
8437
  try {
8405
8438
  const expression = {
@@ -8424,6 +8457,7 @@ function parseFilter(code, locationCalculator, parserOptions) {
8424
8457
  const { ast } = parseScriptFragment(
8425
8458
  `"${calleeCode.trim()}"`,
8426
8459
  subCalculator,
8460
+ vineFixLocationContext,
8427
8461
  parserOptions
8428
8462
  );
8429
8463
  const statement = ast.body[0];
@@ -8467,6 +8501,7 @@ function parseFilter(code, locationCalculator, parserOptions) {
8467
8501
  const result = parseScriptFragment(
8468
8502
  `0${argsCode}`,
8469
8503
  locationCalculator.getSubCalculatorAfter(paren).getSubCalculatorShift(-1),
8504
+ vineFixLocationContext,
8470
8505
  parserOptions
8471
8506
  );
8472
8507
  const { ast } = result;
@@ -8508,6 +8543,9 @@ function parseFilter(code, locationCalculator, parserOptions) {
8508
8543
  }
8509
8544
  function loadParser(parser) {
8510
8545
  if (parser !== "espree") {
8546
+ const __require = createRequire(
8547
+ fileURLToPath2(import.meta.url)
8548
+ );
8511
8549
  return __require(parser);
8512
8550
  }
8513
8551
  return getEspreeFromUser();
@@ -8520,13 +8558,14 @@ function parseScript(code, parserOptions) {
8520
8558
  }
8521
8559
  return { ast: result };
8522
8560
  }
8523
- function parseExpression(code, locationCalculator, parserOptions, { allowEmpty = false, allowFilters = false } = {}) {
8561
+ function parseExpression(code, locationCalculator, vineFixLocationContext, parserOptions, { allowEmpty = false, allowFilters = false } = {}) {
8524
8562
  debug('[script] parse expression: "%s"', code);
8525
8563
  const [mainCode, ...filterCodes] = allowFilters ? splitFilters(code) : [code];
8526
8564
  if (filterCodes.length === 0) {
8527
8565
  return parseExpressionBody(
8528
8566
  code,
8529
8567
  locationCalculator,
8568
+ vineFixLocationContext,
8530
8569
  parserOptions,
8531
8570
  allowEmpty
8532
8571
  );
@@ -8534,6 +8573,7 @@ function parseExpression(code, locationCalculator, parserOptions, { allowEmpty =
8534
8573
  const retB = parseExpressionBody(
8535
8574
  mainCode,
8536
8575
  locationCalculator,
8576
+ vineFixLocationContext,
8537
8577
  parserOptions
8538
8578
  );
8539
8579
  if (!retB.expression) {
@@ -8565,6 +8605,7 @@ function parseExpression(code, locationCalculator, parserOptions, { allowEmpty =
8565
8605
  const retF = parseFilter(
8566
8606
  filterCode,
8567
8607
  locationCalculator.getSubCalculatorShift(prevLoc + 1),
8608
+ vineFixLocationContext,
8568
8609
  parserOptions
8569
8610
  );
8570
8611
  if (retF) {
@@ -8583,7 +8624,7 @@ function parseExpression(code, locationCalculator, parserOptions, { allowEmpty =
8583
8624
  ret.expression.loc.end = lastToken.loc.end;
8584
8625
  return ret;
8585
8626
  }
8586
- function parseVForExpression(code, locationCalculator, parserOptions) {
8627
+ function parseVForExpression(code, locationCalculator, vineFixLocationContext, parserOptions) {
8587
8628
  if (code.trim() === "") {
8588
8629
  throwEmptyError(locationCalculator, "'<alias> in <expression>'");
8589
8630
  }
@@ -8591,6 +8632,7 @@ function parseVForExpression(code, locationCalculator, parserOptions) {
8591
8632
  return parseVForExpressionForEcmaVersion5(
8592
8633
  code,
8593
8634
  locationCalculator,
8635
+ vineFixLocationContext,
8594
8636
  parserOptions
8595
8637
  );
8596
8638
  }
@@ -8610,6 +8652,7 @@ function parseVForExpression(code, locationCalculator, parserOptions) {
8610
8652
  locationCalculator.getSubCalculatorShift(
8611
8653
  processed.hasParens ? -8 : -9
8612
8654
  ),
8655
+ vineFixLocationContext,
8613
8656
  parserOptions
8614
8657
  );
8615
8658
  const { ast } = result;
@@ -8666,6 +8709,7 @@ function parseVForExpression(code, locationCalculator, parserOptions) {
8666
8709
  }
8667
8710
  }
8668
8711
  right.parent = expression;
8712
+ fixVineOffset(expression, vineFixLocationContext);
8669
8713
  return { expression, tokens, comments, references, variables };
8670
8714
  } catch (err) {
8671
8715
  return throwErrorAsAdjustingOutsideOfCode(err, code, locationCalculator);
@@ -8675,7 +8719,7 @@ function isEcmaVersion5(parserOptions) {
8675
8719
  const ecmaVersion = getEcmaVersionIfUseEspree(parserOptions);
8676
8720
  return ecmaVersion != null && ecmaVersion <= 5;
8677
8721
  }
8678
- function parseVForExpressionForEcmaVersion5(code, locationCalculator, parserOptions) {
8722
+ function parseVForExpressionForEcmaVersion5(code, locationCalculator, vineFixLocationContext, parserOptions) {
8679
8723
  const processed = processVForAliasAndIterator(code);
8680
8724
  if (!processed.aliases.trim()) {
8681
8725
  return throwEmptyError(locationCalculator, "an alias");
@@ -8688,6 +8732,7 @@ function parseVForExpressionForEcmaVersion5(code, locationCalculator, parserOpti
8688
8732
  locationCalculator.getSubCalculatorShift(
8689
8733
  processed.hasParens ? 0 : -1
8690
8734
  ),
8735
+ vineFixLocationContext,
8691
8736
  parserOptions
8692
8737
  );
8693
8738
  if (processed.hasParens) {
@@ -8727,6 +8772,7 @@ function parseVForExpressionForEcmaVersion5(code, locationCalculator, parserOpti
8727
8772
  const parsedIterator = parseVForIteratorForEcmaVersion5(
8728
8773
  processed.iterator,
8729
8774
  locationCalculator.getSubCalculatorShift(delimiterEnd),
8775
+ vineFixLocationContext,
8730
8776
  parserOptions
8731
8777
  );
8732
8778
  tokens.push(...parsedIterator.tokens);
@@ -8753,10 +8799,11 @@ function parseVForExpressionForEcmaVersion5(code, locationCalculator, parserOpti
8753
8799
  return throwErrorAsAdjustingOutsideOfCode(err, code, locationCalculator);
8754
8800
  }
8755
8801
  }
8756
- function parseVForAliasesForEcmaVersion5(code, locationCalculator, parserOptions) {
8802
+ function parseVForAliasesForEcmaVersion5(code, locationCalculator, vineFixLocationContext, parserOptions) {
8757
8803
  const result = parseScriptFragment(
8758
8804
  `0(${code})`,
8759
8805
  locationCalculator.getSubCalculatorShift(-2),
8806
+ vineFixLocationContext,
8760
8807
  parserOptions
8761
8808
  );
8762
8809
  const { ast } = result;
@@ -8793,10 +8840,11 @@ function parseVForAliasesForEcmaVersion5(code, locationCalculator, parserOptions
8793
8840
  return ret;
8794
8841
  }
8795
8842
  }
8796
- function parseVForIteratorForEcmaVersion5(code, locationCalculator, parserOptions) {
8843
+ function parseVForIteratorForEcmaVersion5(code, locationCalculator, vineFixLocationContext, parserOptions) {
8797
8844
  const result = parseScriptFragment(
8798
8845
  `0(${code})`,
8799
8846
  locationCalculator.getSubCalculatorShift(-2),
8847
+ vineFixLocationContext,
8800
8848
  parserOptions
8801
8849
  );
8802
8850
  const { ast } = result;
@@ -8818,13 +8866,23 @@ function parseVForIteratorForEcmaVersion5(code, locationCalculator, parserOption
8818
8866
  tokens.pop();
8819
8867
  return { right, tokens, comments, references };
8820
8868
  }
8821
- function parseVOnExpression(code, locationCalculator, parserOptions) {
8869
+ function parseVOnExpression(code, locationCalculator, vineFixLocationContext, parserOptions) {
8822
8870
  if (IS_FUNCTION_EXPRESSION.test(code) || IS_SIMPLE_PATH.test(code)) {
8823
- return parseExpressionBody(code, locationCalculator, parserOptions);
8871
+ return parseExpressionBody(
8872
+ code,
8873
+ locationCalculator,
8874
+ vineFixLocationContext,
8875
+ parserOptions
8876
+ );
8824
8877
  }
8825
- return parseVOnExpressionBody(code, locationCalculator, parserOptions);
8878
+ return parseVOnExpressionBody(
8879
+ code,
8880
+ locationCalculator,
8881
+ vineFixLocationContext,
8882
+ parserOptions
8883
+ );
8826
8884
  }
8827
- function parseVOnExpressionBody(code, locationCalculator, parserOptions) {
8885
+ function parseVOnExpressionBody(code, locationCalculator, vineFixLocationContext, parserOptions) {
8828
8886
  debug('[script] parse v-on expression: "void function($event){%s}"', code);
8829
8887
  if (code.trim() === "") {
8830
8888
  throwEmptyError(locationCalculator, "statements");
@@ -8833,6 +8891,7 @@ function parseVOnExpressionBody(code, locationCalculator, parserOptions) {
8833
8891
  const result = parseScriptFragment(
8834
8892
  `void function($event){${code}}`,
8835
8893
  locationCalculator.getSubCalculatorShift(-22),
8894
+ vineFixLocationContext,
8836
8895
  parserOptions
8837
8896
  );
8838
8897
  const { ast } = result;
@@ -8863,12 +8922,13 @@ function parseVOnExpressionBody(code, locationCalculator, parserOptions) {
8863
8922
  }
8864
8923
  tokens.splice(0, 6);
8865
8924
  tokens.pop();
8925
+ fixVineOffset(expression, vineFixLocationContext);
8866
8926
  return { expression, tokens, comments, references, variables: [] };
8867
8927
  } catch (err) {
8868
8928
  return throwErrorAsAdjustingOutsideOfCode(err, code, locationCalculator);
8869
8929
  }
8870
8930
  }
8871
- function parseSlotScopeExpression(code, locationCalculator, parserOptions) {
8931
+ function parseSlotScopeExpression(code, locationCalculator, vineFixLocationContext, parserOptions) {
8872
8932
  debug('[script] parse slot-scope expression: "void function(%s) {}"', code);
8873
8933
  if (code.trim() === "") {
8874
8934
  throwEmptyError(
@@ -8880,6 +8940,7 @@ function parseSlotScopeExpression(code, locationCalculator, parserOptions) {
8880
8940
  const result = parseScriptFragment(
8881
8941
  `void function(${code}) {}`,
8882
8942
  locationCalculator.getSubCalculatorShift(-14),
8943
+ vineFixLocationContext,
8883
8944
  parserOptions
8884
8945
  );
8885
8946
  const { ast } = result;
@@ -8952,7 +9013,7 @@ function getStandardDirectiveKind(element, directiveKey) {
8952
9013
  }
8953
9014
  return null;
8954
9015
  }
8955
- function parseAttributeValue(code, parserOptions, globalLocationCalculator, node, element, directiveKey) {
9016
+ function parseAttributeValue(code, parserOptions, globalLocationCalculator, vineFixLocationContext, node, element, directiveKey) {
8956
9017
  const firstChar = code[node.range[0]];
8957
9018
  const quoted = firstChar === '"' || firstChar === "'";
8958
9019
  const locationCalculator = globalLocationCalculator.getSubCalculatorAfter(
@@ -8975,29 +9036,38 @@ function parseAttributeValue(code, parserOptions, globalLocationCalculator, node
8975
9036
  result = parseVForExpression(
8976
9037
  node.value,
8977
9038
  locationCalculator,
9039
+ vineFixLocationContext,
8978
9040
  parserOptions
8979
9041
  );
8980
9042
  } else if (directiveKind === "on" && directiveKey.argument != null) {
8981
9043
  result = parseVOnExpression(
8982
9044
  node.value,
8983
9045
  locationCalculator,
9046
+ vineFixLocationContext,
8984
9047
  parserOptions
8985
9048
  );
8986
9049
  } else if (directiveKind === "slot") {
8987
9050
  result = parseSlotScopeExpression(
8988
9051
  node.value,
8989
9052
  locationCalculator,
9053
+ vineFixLocationContext,
8990
9054
  parserOptions
8991
9055
  );
8992
9056
  } else if (directiveKind === "bind") {
8993
9057
  result = parseExpression(
8994
9058
  node.value,
8995
9059
  locationCalculator,
9060
+ vineFixLocationContext,
8996
9061
  parserOptions,
8997
9062
  { allowFilters: true }
8998
9063
  );
8999
9064
  } else {
9000
- result = parseExpression(node.value, locationCalculator, parserOptions);
9065
+ result = parseExpression(
9066
+ node.value,
9067
+ locationCalculator,
9068
+ vineFixLocationContext,
9069
+ parserOptions
9070
+ );
9001
9071
  }
9002
9072
  if (quoted) {
9003
9073
  result.tokens.unshift(
@@ -9021,7 +9091,7 @@ function parseAttributeValue(code, parserOptions, globalLocationCalculator, node
9021
9091
  }
9022
9092
  return result;
9023
9093
  }
9024
- function parseDirectiveKeyStatically(node, templateMeta) {
9094
+ function parseDirectiveKeyStatically(node, templateMeta, vineFixLocationContext) {
9025
9095
  const {
9026
9096
  name: text,
9027
9097
  rawName: rawText,
@@ -9039,9 +9109,10 @@ function parseDirectiveKeyStatically(node, templateMeta) {
9039
9109
  argument: null,
9040
9110
  modifiers: []
9041
9111
  };
9112
+ fixVineOffset(directiveKey, vineFixLocationContext);
9042
9113
  let i = 0;
9043
- function createIdentifier(start, end, name) {
9044
- return {
9114
+ function createIdentifier(vineFixLocationContext2, start, end, name) {
9115
+ const id = {
9045
9116
  type: "VIdentifier",
9046
9117
  parent: directiveKey,
9047
9118
  range: [offset + start, offset + end],
@@ -9052,27 +9123,29 @@ function parseDirectiveKeyStatically(node, templateMeta) {
9052
9123
  name: name || text.slice(start, end),
9053
9124
  rawName: rawText.slice(start, end)
9054
9125
  };
9126
+ fixVineOffset(id, vineFixLocationContext2);
9127
+ return id;
9055
9128
  }
9056
9129
  if (shorthandSign.test(text)) {
9057
9130
  const sign = text[0];
9058
- directiveKey.name = createIdentifier(0, 1, shorthandNameMap[sign]);
9131
+ directiveKey.name = createIdentifier(vineFixLocationContext, 0, 1, shorthandNameMap[sign]);
9059
9132
  i = 1;
9060
9133
  } else {
9061
9134
  const colon = text.indexOf(":");
9062
9135
  if (colon !== -1) {
9063
- directiveKey.name = createIdentifier(0, colon);
9136
+ directiveKey.name = createIdentifier(vineFixLocationContext, 0, colon);
9064
9137
  i = colon + 1;
9065
9138
  }
9066
9139
  }
9067
9140
  if (directiveKey.name != null && text[i] === "[") {
9068
9141
  const len = text.slice(i).lastIndexOf("]");
9069
9142
  if (len !== -1) {
9070
- directiveKey.argument = createIdentifier(i, i + len + 1);
9143
+ directiveKey.argument = createIdentifier(vineFixLocationContext, i, i + len + 1);
9071
9144
  i = i + len + 1 + (text[i + len + 1] === "." ? 1 : 0);
9072
9145
  }
9073
9146
  }
9074
9147
  const modifiers = text.slice(i).split(".").map((modifierName) => {
9075
- const modifier = createIdentifier(i, i + modifierName.length);
9148
+ const modifier = createIdentifier(vineFixLocationContext, i, i + modifierName.length);
9076
9149
  if (modifierName === "" && i < text.length) {
9077
9150
  insertError(
9078
9151
  templateMeta,
@@ -9108,7 +9181,7 @@ function parseDirectiveKeyStatically(node, templateMeta) {
9108
9181
  }
9109
9182
  if (directiveKey.name.rawName === "." && !directiveKey.modifiers.some(isPropModifier)) {
9110
9183
  const pos = (directiveKey.argument || directiveKey.name).range[1] - offset;
9111
- const propModifier = createIdentifier(pos, pos, "prop");
9184
+ const propModifier = createIdentifier(vineFixLocationContext, pos, pos, "prop");
9112
9185
  directiveKey.modifiers.unshift(propModifier);
9113
9186
  }
9114
9187
  return directiveKey;
@@ -9171,7 +9244,7 @@ function parseDirectiveKeyTokens(node) {
9171
9244
  }
9172
9245
  return tokens;
9173
9246
  }
9174
- function convertDynamicArgument(node, templateMeta, parserOptions, locationCalculator) {
9247
+ function convertDynamicArgument(node, templateMeta, parserOptions, locationCalculator, vineFixLocationContext) {
9175
9248
  const { argument } = node;
9176
9249
  if (!(argument != null && argument.type === "VIdentifier" && argument.name.startsWith("[") && argument.name.endsWith("]"))) {
9177
9250
  return;
@@ -9181,6 +9254,7 @@ function convertDynamicArgument(node, templateMeta, parserOptions, locationCalcu
9181
9254
  const { comments, expression, references, tokens } = parseExpression(
9182
9255
  rawName.slice(1, -1),
9183
9256
  locationCalculator.getSubCalculatorAfter(range[0] + 1),
9257
+ vineFixLocationContext,
9184
9258
  parserOptions
9185
9259
  );
9186
9260
  node.argument = {
@@ -9191,6 +9265,7 @@ function convertDynamicArgument(node, templateMeta, parserOptions, locationCalcu
9191
9265
  expression,
9192
9266
  references
9193
9267
  };
9268
+ fixVineOffset(node.argument, vineFixLocationContext);
9194
9269
  if (expression != null) {
9195
9270
  expression.parent = node.argument;
9196
9271
  }
@@ -9231,8 +9306,8 @@ function convertDynamicArgument(node, templateMeta, parserOptions, locationCalcu
9231
9306
  }
9232
9307
  }
9233
9308
  }
9234
- function createDirectiveKey(node, templateMeta, parserOptions, locationCalculator) {
9235
- const directiveKey = parseDirectiveKeyStatically(node, templateMeta);
9309
+ function createDirectiveKey(node, templateMeta, parserOptions, locationCalculator, vineFixLocationContext) {
9310
+ const directiveKey = parseDirectiveKeyStatically(node, templateMeta, vineFixLocationContext);
9236
9311
  const tokens = parseDirectiveKeyTokens(directiveKey);
9237
9312
  replaceTokens(templateMeta, directiveKey, tokens);
9238
9313
  if (directiveKey.name.name.startsWith("v-")) {
@@ -9245,11 +9320,12 @@ function createDirectiveKey(node, templateMeta, parserOptions, locationCalculato
9245
9320
  directiveKey,
9246
9321
  templateMeta,
9247
9322
  parserOptions,
9248
- locationCalculator
9323
+ locationCalculator,
9324
+ vineFixLocationContext
9249
9325
  );
9250
9326
  return directiveKey;
9251
9327
  }
9252
- function convertToDirective(node, code, templateMeta, locationCalculator, parserOptions) {
9328
+ function convertToDirective(node, code, templateMeta, locationCalculator, vineFixLocationContext, parserOptions) {
9253
9329
  debug(
9254
9330
  '[template] convert to directive: %s="%s" %j',
9255
9331
  node.key.name,
@@ -9262,7 +9338,12 @@ function convertToDirective(node, code, templateMeta, locationCalculator, parser
9262
9338
  node.key,
9263
9339
  templateMeta,
9264
9340
  parserOptions,
9265
- locationCalculator
9341
+ locationCalculator,
9342
+ vineFixLocationContext
9343
+ );
9344
+ fixVineOffset(
9345
+ directive.key,
9346
+ vineFixLocationContext
9266
9347
  );
9267
9348
  const { argument } = directive.key;
9268
9349
  if (argument && argument.type === "VIdentifier" && argument.name.startsWith("[")) {
@@ -9289,6 +9370,7 @@ function convertToDirective(node, code, templateMeta, locationCalculator, parser
9289
9370
  code,
9290
9371
  parserOptions,
9291
9372
  locationCalculator,
9373
+ vineFixLocationContext,
9292
9374
  node.value,
9293
9375
  node.parent.parent,
9294
9376
  directive.key
@@ -9301,6 +9383,10 @@ function convertToDirective(node, code, templateMeta, locationCalculator, parser
9301
9383
  expression: ret.expression,
9302
9384
  references: ret.references
9303
9385
  };
9386
+ fixVineOffset(
9387
+ directive.value,
9388
+ vineFixLocationContext
9389
+ );
9304
9390
  if (ret.expression != null) {
9305
9391
  ret.expression.parent = directive.value;
9306
9392
  }
@@ -9326,7 +9412,7 @@ function convertToDirective(node, code, templateMeta, locationCalculator, parser
9326
9412
  }
9327
9413
  }
9328
9414
  }
9329
- function processMustache(parserOptions, globalLocationCalculator, templateMeta, node, mustache) {
9415
+ function processMustache(parserOptions, globalLocationCalculator, vineFixLocationContext, templateMeta, node, mustache) {
9330
9416
  const range = [
9331
9417
  mustache.startToken.range[1],
9332
9418
  mustache.endToken.range[0]
@@ -9337,6 +9423,7 @@ function processMustache(parserOptions, globalLocationCalculator, templateMeta,
9337
9423
  const ret = parseExpression(
9338
9424
  mustache.value,
9339
9425
  locationCalculator,
9426
+ vineFixLocationContext,
9340
9427
  parserOptions,
9341
9428
  { allowEmpty: true, allowFilters: true }
9342
9429
  );
@@ -9538,31 +9625,22 @@ var VineTemplateParser = class {
9538
9625
  };
9539
9626
  this.expressionEnabled = true;
9540
9627
  }
9628
+ get fixVineOffsetCtx() {
9629
+ return {
9630
+ posInfo: this.templatePos,
9631
+ fixedCache: this.offsetFixedTokenSet
9632
+ };
9633
+ }
9541
9634
  correctMetaTokenPos() {
9542
9635
  this.vTemplateMeta.tokens.forEach((token) => fixVineOffset(
9543
9636
  token,
9544
- this.templatePos,
9545
- this.offsetFixedTokenSet
9637
+ this.fixVineOffsetCtx
9546
9638
  ));
9547
9639
  this.vTemplateMeta.comments.forEach((comment) => fixVineOffset(
9548
9640
  comment,
9549
- this.templatePos,
9550
- this.offsetFixedTokenSet
9641
+ this.fixVineOffsetCtx
9551
9642
  ));
9552
- fixVineOffset(this.vTemplateRoot, this.templatePos, this.offsetFixedTokenSet);
9553
- }
9554
- correctESTreeTokenPos() {
9555
- traverseNodes(this.vTemplateRoot, {
9556
- enterNode: (node) => {
9557
- fixVineOffset(
9558
- node,
9559
- this.templatePos,
9560
- this.offsetFixedTokenSet
9561
- );
9562
- },
9563
- leaveNode: () => {
9564
- }
9565
- });
9643
+ fixVineOffset(this.vTemplateRoot, this.fixVineOffsetCtx);
9566
9644
  }
9567
9645
  /**
9568
9646
  * Get the current node.
@@ -9692,6 +9770,7 @@ var VineTemplateParser = class {
9692
9770
  this.text,
9693
9771
  this.vTemplateMeta,
9694
9772
  this.locationCalculator,
9773
+ this.fixVineOffsetCtx,
9695
9774
  parserOptions
9696
9775
  );
9697
9776
  }
@@ -9877,6 +9956,7 @@ var VineTemplateParser = class {
9877
9956
  processMustache(
9878
9957
  parserOptions,
9879
9958
  this.locationCalculator,
9959
+ this.fixVineOffsetCtx,
9880
9960
  this.vTemplateMeta,
9881
9961
  container,
9882
9962
  token
@@ -9905,7 +9985,6 @@ var VineTemplateParser = class {
9905
9985
  }
9906
9986
  this.postProcessForScript = [];
9907
9987
  this.correctMetaTokenPos();
9908
- this.correctESTreeTokenPos();
9909
9988
  return [templateRoot, templateMeta];
9910
9989
  }
9911
9990
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue-vine/eslint-parser",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "ESLint parser for Vue Vine",
5
5
  "author": "ShenQingchuan",
6
6
  "license": "MIT",