@markuplint/pug-parser 3.10.0 → 4.0.0-alpha.2

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.
@@ -1,3 +1,3 @@
1
- import type { ASTAttr } from './pug-parser';
1
+ import type { ASTAttr } from './pug-parser/index.js';
2
2
  import type { MLASTAttr } from '@markuplint/ml-ast';
3
3
  export default function attrTokenizer(attr: ASTAttr): MLASTAttr;
@@ -1,21 +1,18 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const parser_utils_1 = require("@markuplint/parser-utils");
4
- function attrTokenizer(
1
+ import { tokenizer, uuid } from '@markuplint/parser-utils';
2
+ export default function attrTokenizer(
5
3
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
6
4
  attr) {
7
- var _a, _b, _c;
8
5
  if (attr.raw[0] === '#' || attr.raw[0] === '.') {
9
6
  let value = '';
10
7
  if (typeof attr.val === 'string') {
11
- [, , value] = (_a = attr.val.match(/(['"`]?)([^\1]+)(\1)/)) !== null && _a !== void 0 ? _a : ['', '', ''];
8
+ [, , value] = attr.val.match(/(['"`]?)([^\1]+)(\1)/) ?? ['', '', ''];
12
9
  }
13
10
  else {
14
11
  value = `${attr.val}`;
15
12
  }
16
13
  return {
17
14
  type: 'ps-attr',
18
- uuid: (0, parser_utils_1.uuid)(),
15
+ uuid: uuid(),
19
16
  raw: attr.raw,
20
17
  startOffset: attr.offset,
21
18
  endOffset: attr.endOffset,
@@ -24,7 +21,7 @@ attr) {
24
21
  startCol: attr.column,
25
22
  endCol: attr.endColumn,
26
23
  potentialName: attr.name,
27
- potentialValue: value !== null && value !== void 0 ? value : '',
24
+ potentialValue: value ?? '',
28
25
  valueType: 'string',
29
26
  isDuplicatable: attr.raw[0] === '.',
30
27
  nodeName: '#pug-special-attr',
@@ -54,13 +51,13 @@ attr) {
54
51
  const withoutName = attr.raw.slice(attr.name.length);
55
52
  const valueOffset = withoutName.indexOf(attr.val);
56
53
  const equalAndBeforeSpaceAfterSpace = withoutName.slice(0, valueOffset);
57
- const [, before, equal, after] = (_b = equalAndBeforeSpaceAfterSpace.match(/^(\s*)(=)(\s*)$/)) !== null && _b !== void 0 ? _b : ['', '', '', ''];
58
- const [, quote, coreValue] = (_c = attr.val.match(/(['"`]?)([^\1]+)(\1)/)) !== null && _c !== void 0 ? _c : ['', '', ''];
59
- spacesBeforeEqualChars = before !== null && before !== void 0 ? before : '';
60
- equalChars = equal !== null && equal !== void 0 ? equal : '';
61
- spacesAfterEqualChars = after !== null && after !== void 0 ? after : '';
62
- quoteChars = quote !== null && quote !== void 0 ? quote : '';
63
- valueChars = coreValue !== null && coreValue !== void 0 ? coreValue : '';
54
+ const [, before, equal, after] = equalAndBeforeSpaceAfterSpace.match(/^(\s*)(=)(\s*)$/) ?? ['', '', '', ''];
55
+ const [, quote, coreValue] = attr.val.match(/(['"`]?)([^\1]+)(\1)/) ?? ['', '', ''];
56
+ spacesBeforeEqualChars = before ?? '';
57
+ equalChars = equal ?? '';
58
+ spacesAfterEqualChars = after ?? '';
59
+ quoteChars = quote ?? '';
60
+ valueChars = coreValue ?? '';
64
61
  if (quote === '`' || quote === '') {
65
62
  isDynamicValue = true;
66
63
  }
@@ -73,36 +70,36 @@ attr) {
73
70
  let offset = attr.offset;
74
71
  let line = attr.line;
75
72
  let col = attr.column;
76
- const attrToken = (0, parser_utils_1.tokenizer)(attr.raw, line, col, offset);
77
- const spacesBeforeName = (0, parser_utils_1.tokenizer)(spacesBeforeAttrString, line, col, offset);
73
+ const attrToken = tokenizer(attr.raw, line, col, offset);
74
+ const spacesBeforeName = tokenizer(spacesBeforeAttrString, line, col, offset);
78
75
  line = spacesBeforeName.endLine;
79
76
  col = spacesBeforeName.endCol;
80
77
  offset = spacesBeforeName.endOffset;
81
- const name = (0, parser_utils_1.tokenizer)(nameChars, line, col, offset);
78
+ const name = tokenizer(nameChars, line, col, offset);
82
79
  line = name.endLine;
83
80
  col = name.endCol;
84
81
  offset = name.endOffset;
85
- const spacesBeforeEqual = (0, parser_utils_1.tokenizer)(spacesBeforeEqualChars, line, col, offset);
82
+ const spacesBeforeEqual = tokenizer(spacesBeforeEqualChars, line, col, offset);
86
83
  line = spacesBeforeEqual.endLine;
87
84
  col = spacesBeforeEqual.endCol;
88
85
  offset = spacesBeforeEqual.endOffset;
89
- const equal = (0, parser_utils_1.tokenizer)(equalChars, line, col, offset);
86
+ const equal = tokenizer(equalChars, line, col, offset);
90
87
  line = equal.endLine;
91
88
  col = equal.endCol;
92
89
  offset = equal.endOffset;
93
- const spacesAfterEqual = (0, parser_utils_1.tokenizer)(spacesAfterEqualChars, line, col, offset);
90
+ const spacesAfterEqual = tokenizer(spacesAfterEqualChars, line, col, offset);
94
91
  line = spacesAfterEqual.endLine;
95
92
  col = spacesAfterEqual.endCol;
96
93
  offset = spacesAfterEqual.endOffset;
97
- const startQuote = (0, parser_utils_1.tokenizer)(quoteChars, line, col, offset);
94
+ const startQuote = tokenizer(quoteChars, line, col, offset);
98
95
  line = startQuote.endLine;
99
96
  col = startQuote.endCol;
100
97
  offset = startQuote.endOffset;
101
- const value = (0, parser_utils_1.tokenizer)(valueChars, line, col, offset);
98
+ const value = tokenizer(valueChars, line, col, offset);
102
99
  line = value.endLine;
103
100
  col = value.endCol;
104
101
  offset = value.endOffset;
105
- const endQuote = (0, parser_utils_1.tokenizer)(quoteChars, line, col, offset);
102
+ const endQuote = tokenizer(quoteChars, line, col, offset);
106
103
  line = endQuote.endLine;
107
104
  col = endQuote.endCol;
108
105
  offset = endQuote.endOffset;
@@ -112,7 +109,7 @@ attr) {
112
109
  }
113
110
  return {
114
111
  type: 'html-attr',
115
- uuid: (0, parser_utils_1.uuid)(),
112
+ uuid: uuid(),
116
113
  raw: attrToken.raw,
117
114
  startOffset: attrToken.startOffset,
118
115
  endOffset: attrToken.endOffset,
@@ -138,4 +135,3 @@ attr) {
138
135
  isGhost: false,
139
136
  };
140
137
  }
141
- exports.default = attrTokenizer;
package/lib/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { parse } from './parse';
1
+ export { parse } from './parse.js';
2
2
  export declare const endTag = "never";
package/lib/index.js CHANGED
@@ -1,6 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.endTag = exports.parse = void 0;
4
- var parse_1 = require("./parse");
5
- Object.defineProperty(exports, "parse", { enumerable: true, get: function () { return parse_1.parse; } });
6
- exports.endTag = 'never';
1
+ export { parse } from './parse.js';
2
+ export const endTag = 'never';
package/lib/parse.js CHANGED
@@ -1,17 +1,14 @@
1
- "use strict";
2
1
  var _Parser_ast;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.parse = void 0;
5
- const tslib_1 = require("tslib");
6
- const html_parser_1 = require("@markuplint/html-parser");
7
- const parser_utils_1 = require("@markuplint/parser-utils");
8
- const attr_tokenizer_1 = tslib_1.__importDefault(require("./attr-tokenizer"));
9
- const pug_parser_1 = require("./pug-parser");
10
- const parse = (rawCode, options) => {
2
+ import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
3
+ import { getNamespace, parse as htmlParser, isDocumentFragment } from '@markuplint/html-parser';
4
+ import { detectElementType, ignoreFrontMatter, ParserError, tokenizer, uuid, walk, removeDeprecatedNode, } from '@markuplint/parser-utils';
5
+ import attrTokenizer from './attr-tokenizer.js';
6
+ import { pugParse } from './pug-parser/index.js';
7
+ export const parse = (rawCode, options) => {
11
8
  let unknownParseError;
12
9
  let nodeList;
13
- if (options === null || options === void 0 ? void 0 : options.ignoreFrontMatter) {
14
- rawCode = (0, parser_utils_1.ignoreFrontMatter)(rawCode);
10
+ if (options?.ignoreFrontMatter) {
11
+ rawCode = ignoreFrontMatter(rawCode);
15
12
  }
16
13
  try {
17
14
  const parser = new Parser(rawCode);
@@ -20,7 +17,7 @@ const parse = (rawCode, options) => {
20
17
  catch (err) {
21
18
  nodeList = [];
22
19
  if (err instanceof Error && 'msg' in err && 'line' in err && 'column' in err && 'src' in err) {
23
- throw new parser_utils_1.ParserError(
20
+ throw new ParserError(
24
21
  // @ts-ignore
25
22
  err.msg, {
26
23
  // @ts-ignore
@@ -35,29 +32,28 @@ const parse = (rawCode, options) => {
35
32
  }
36
33
  return {
37
34
  nodeList,
38
- isFragment: (0, html_parser_1.isDocumentFragment)(rawCode),
35
+ isFragment: isDocumentFragment(rawCode),
39
36
  unknownParseError: unknownParseError,
40
37
  };
41
38
  };
42
- exports.parse = parse;
43
39
  class Parser {
44
40
  constructor(raw) {
45
41
  _Parser_ast.set(this, void 0);
46
- tslib_1.__classPrivateFieldSet(this, _Parser_ast, (0, pug_parser_1.pugParse)(raw), "f");
42
+ __classPrivateFieldSet(this, _Parser_ast, pugParse(raw), "f");
47
43
  // console.log(JSON.stringify(this.#ast, null, 2));
48
44
  }
49
45
  flattenNodes(
50
46
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
51
47
  nodeTree) {
52
48
  const nodeOrders = [];
53
- (0, parser_utils_1.walk)(nodeTree, node => {
49
+ walk(nodeTree, node => {
54
50
  nodeOrders.push(node);
55
51
  });
56
- (0, parser_utils_1.removeDeprecatedNode)(nodeOrders);
52
+ removeDeprecatedNode(nodeOrders);
57
53
  return nodeOrders;
58
54
  }
59
55
  getNodeList() {
60
- const nodeTree = this.traverse(tslib_1.__classPrivateFieldGet(this, _Parser_ast, "f").nodes, null);
56
+ const nodeTree = this.traverse(__classPrivateFieldGet(this, _Parser_ast, "f").nodes, null);
61
57
  return this.flattenNodes(nodeTree);
62
58
  }
63
59
  nodeize(
@@ -67,7 +63,6 @@ class Parser {
67
63
  prevNode,
68
64
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
69
65
  parentNode) {
70
- var _a;
71
66
  const nextNode = null;
72
67
  const startOffset = originNode.offset;
73
68
  const endOffset = originNode.endOffset;
@@ -79,9 +74,9 @@ class Parser {
79
74
  switch (originNode.type) {
80
75
  case 'Doctype': {
81
76
  return {
82
- uuid: (0, parser_utils_1.uuid)(),
77
+ uuid: uuid(),
83
78
  raw: originNode.raw,
84
- name: (_a = originNode.val) !== null && _a !== void 0 ? _a : '',
79
+ name: originNode.val ?? '',
85
80
  // TODO:
86
81
  publicId: '',
87
82
  // TODO:
@@ -105,7 +100,7 @@ class Parser {
105
100
  case 'Text': {
106
101
  if (parentNode && /^script$|^style$/i.test(parentNode.nodeName)) {
107
102
  return {
108
- uuid: (0, parser_utils_1.uuid)(),
103
+ uuid: uuid(),
109
104
  raw: originNode.raw,
110
105
  startOffset,
111
106
  endOffset,
@@ -122,7 +117,7 @@ class Parser {
122
117
  isGhost: false,
123
118
  };
124
119
  }
125
- const htmlDoc = (0, html_parser_1.parse)(originNode.raw, {
120
+ const htmlDoc = htmlParser(originNode.raw, {
126
121
  offsetOffset: originNode.offset,
127
122
  offsetLine: originNode.line - 1,
128
123
  offsetColumn: originNode.column - 1,
@@ -137,7 +132,7 @@ class Parser {
137
132
  }
138
133
  case 'Comment': {
139
134
  return {
140
- uuid: (0, parser_utils_1.uuid)(),
135
+ uuid: uuid(),
141
136
  raw: originNode.raw,
142
137
  startOffset,
143
138
  endOffset,
@@ -155,9 +150,9 @@ class Parser {
155
150
  };
156
151
  }
157
152
  case 'Tag': {
158
- const namespace = (0, html_parser_1.getNamespace)(originNode.name, parentNamespace);
153
+ const namespace = getNamespace(originNode.name, parentNamespace);
159
154
  const tag = {
160
- uuid: (0, parser_utils_1.uuid)(),
155
+ uuid: uuid(),
161
156
  raw: originNode.raw,
162
157
  startOffset,
163
158
  endOffset,
@@ -168,15 +163,15 @@ class Parser {
168
163
  nodeName: originNode.name,
169
164
  type: 'starttag',
170
165
  namespace,
171
- elementType: (0, parser_utils_1.detectElementType)(originNode.name),
172
- attributes: originNode.attrs.map(attr => (0, attr_tokenizer_1.default)(attr)),
166
+ elementType: detectElementType(originNode.name),
167
+ attributes: originNode.attrs.map(attr => attrTokenizer(attr)),
173
168
  hasSpreadAttr: false,
174
169
  parentNode,
175
170
  prevNode,
176
171
  nextNode,
177
172
  pearNode: null,
178
- selfClosingSolidus: (0, parser_utils_1.tokenizer)('', originNode.line, originNode.column, originNode.offset),
179
- endSpace: (0, parser_utils_1.tokenizer)('', originNode.line, originNode.column, originNode.offset),
173
+ selfClosingSolidus: tokenizer('', originNode.line, originNode.column, originNode.offset),
174
+ endSpace: tokenizer('', originNode.line, originNode.column, originNode.offset),
180
175
  isFragment: false,
181
176
  isGhost: false,
182
177
  tagOpenChar: '',
@@ -189,7 +184,7 @@ class Parser {
189
184
  }
190
185
  default: {
191
186
  const tag = {
192
- uuid: (0, parser_utils_1.uuid)(),
187
+ uuid: uuid(),
193
188
  raw: originNode.raw,
194
189
  startOffset,
195
190
  endOffset,
@@ -1,22 +1,17 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.pugParse = void 0;
4
- const tslib_1 = require("tslib");
5
1
  // @ts-ignore
6
- const pug_lexer_1 = tslib_1.__importDefault(require("pug-lexer"));
2
+ import lexer from 'pug-lexer';
7
3
  // @ts-ignore
8
- const pug_parser_1 = tslib_1.__importDefault(require("pug-parser"));
9
- const get_offset_from_line_and_col_1 = require("../utils/get-offset-from-line-and-col");
10
- function pugParse(pug) {
11
- const lexOrigin = (0, pug_lexer_1.default)(pug);
4
+ import parser from 'pug-parser';
5
+ import { getOffsetFromLineAndCol } from '../utils/get-offset-from-line-and-col.js';
6
+ export function pugParse(pug) {
7
+ const lexOrigin = lexer(pug);
12
8
  const lex = JSON.parse(JSON.stringify(lexOrigin));
13
- const originAst = (0, pug_parser_1.default)(lexOrigin);
9
+ const originAst = parser(lexOrigin);
14
10
  // console.log(lex);
15
11
  // console.log(JSON.stringify(originAst, null, 2));
16
12
  const ast = optimizeAST(originAst, lex, pug);
17
13
  return ast;
18
14
  }
19
- exports.pugParse = pugParse;
20
15
  function getOffsetsFromLines(pug) {
21
16
  const lines = pug.split(/\n/g);
22
17
  let chars = 0;
@@ -29,10 +24,9 @@ function getOffsetsFromLines(pug) {
29
24
  function mergeTextNode(
30
25
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
31
26
  nodes, pug) {
32
- var _a;
33
27
  const baseNodes = [];
34
28
  for (const node of nodes) {
35
- const prevNode = (_a = baseNodes[baseNodes.length - 1]) !== null && _a !== void 0 ? _a : null;
29
+ const prevNode = baseNodes[baseNodes.length - 1] ?? null;
36
30
  if (prevNode && prevNode.type === 'Text' && node.type === 'Text') {
37
31
  prevNode.raw = pug.slice(prevNode.offset, node.endOffset);
38
32
  prevNode.endColumn = node.endColumn;
@@ -55,13 +49,12 @@ function optimizeAST(
55
49
  originalAST,
56
50
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
57
51
  tokens, pug) {
58
- var _a;
59
52
  const nodes = [];
60
53
  for (const node of originalAST.nodes) {
61
54
  const line = node.line;
62
55
  const column = node.column;
63
56
  const offsets = getOffsetsFromLines(pug);
64
- const lineOffset = Math.max((_a = offsets[line - 2]) !== null && _a !== void 0 ? _a : 0, 0);
57
+ const lineOffset = Math.max(offsets[line - 2] ?? 0, 0);
65
58
  const offset = lineOffset + column - 1;
66
59
  const { endLine, endColumn, endOffset } = getLocationFromToken(offset, line, column, tokens);
67
60
  const raw = pug.slice(offset, endOffset);
@@ -316,7 +309,6 @@ function optimizeASTOfConditionalNode(
316
309
  node,
317
310
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
318
311
  tokens, pug, offsets, depth) {
319
- var _a, _b;
320
312
  const altNodes = [];
321
313
  let tokenOfCurrentNode = null;
322
314
  for (const token of tokens) {
@@ -327,7 +319,7 @@ tokens, pug, offsets, depth) {
327
319
  }
328
320
  if (tokenOfCurrentNode) {
329
321
  // console.log(JSON.stringify(node, null, 2));
330
- const lineOffset = Math.max((_a = offsets[node.line - 2]) !== null && _a !== void 0 ? _a : 0, 0);
322
+ const lineOffset = Math.max(offsets[node.line - 2] ?? 0, 0);
331
323
  const offset = lineOffset + node.column - 1;
332
324
  const length = tokenOfCurrentNode.loc.end.column - tokenOfCurrentNode.loc.start.column;
333
325
  const endOffset = offset + length;
@@ -359,7 +351,7 @@ tokens, pug, offsets, depth) {
359
351
  if (!tokenOfCurrentNode) {
360
352
  return [];
361
353
  }
362
- const lineOffset = Math.max((_b = offsets[tokenOfCurrentNode.loc.start.line - 2]) !== null && _b !== void 0 ? _b : 0, 0);
354
+ const lineOffset = Math.max(offsets[tokenOfCurrentNode.loc.start.line - 2] ?? 0, 0);
363
355
  const offset = lineOffset + tokenOfCurrentNode.loc.start.column - 1;
364
356
  const length = tokenOfCurrentNode.loc.end.column - tokenOfCurrentNode.loc.start.column;
365
357
  const endOffset = offset + length;
@@ -390,7 +382,7 @@ tokens, pug, offsets, depth) {
390
382
  function getLocationFromToken(offset, line, column,
391
383
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
392
384
  tokens, tokenType) {
393
- const tokenTypes = typeof tokenType === 'string' ? (tokenType !== '' ? [tokenType] : null) : tokenType !== null && tokenType !== void 0 ? tokenType : null;
385
+ const tokenTypes = typeof tokenType === 'string' ? (tokenType !== '' ? [tokenType] : null) : tokenType ?? null;
394
386
  let tokenOfCurrentNode = null;
395
387
  for (const token of tokens) {
396
388
  if ((tokenTypes == null || tokenTypes.includes(token.type)) &&
@@ -416,10 +408,9 @@ function getAttrs(
416
408
  originalAttrs,
417
409
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
418
410
  tokens, offsets, pug) {
419
- var _a;
420
411
  const attrs = [];
421
412
  for (const attr of originalAttrs) {
422
- const attrLineOffset = (_a = offsets[attr.line - 2]) !== null && _a !== void 0 ? _a : 0;
413
+ const attrLineOffset = offsets[attr.line - 2] ?? 0;
423
414
  const attrOffset = attrLineOffset + attr.column - 1;
424
415
  let tokenOfCurrentAttr = null;
425
416
  for (const token of tokens) {
@@ -452,7 +443,6 @@ tokens, offsets, pug) {
452
443
  function getEndAttributeLocation(nodeName, offset, line, column,
453
444
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
454
445
  tokens, offsets) {
455
- var _a;
456
446
  let beforeNewlineToken = null;
457
447
  for (const token of tokens) {
458
448
  // Searching token after the tag node.
@@ -463,7 +453,7 @@ tokens, offsets) {
463
453
  token.type !== 'end-attributes' &&
464
454
  token.type !== 'id' &&
465
455
  token.type !== 'class') {
466
- const endAttrLineOffset = Math.max((_a = offsets[beforeNewlineToken.loc.end.line - 2]) !== null && _a !== void 0 ? _a : 0, 0);
456
+ const endAttrLineOffset = Math.max(offsets[beforeNewlineToken.loc.end.line - 2] ?? 0, 0);
467
457
  const endAttrOffset = endAttrLineOffset + beforeNewlineToken.loc.end.column - 1;
468
458
  return {
469
459
  endOffset: endAttrOffset,
@@ -500,8 +490,8 @@ tokens) {
500
490
  if (startPipelessText.loc.start.line < node.line && node.line < endPipelessText.loc.start.line) {
501
491
  const { line, column } = startPipelessText.loc.start;
502
492
  const { line: endLine, column: endColumn } = endPipelessText.loc.end;
503
- const offset = (0, get_offset_from_line_and_col_1.getOffsetFromLineAndCol)(pug, line, column);
504
- const endOffset = (0, get_offset_from_line_and_col_1.getOffsetFromLineAndCol)(pug, endLine, endColumn);
493
+ const offset = getOffsetFromLineAndCol(pug, line, column);
494
+ const endOffset = getOffsetFromLineAndCol(pug, endLine, endColumn);
505
495
  const raw = pug.slice(offset, endOffset);
506
496
  return {
507
497
  raw,
@@ -518,7 +508,6 @@ tokens) {
518
508
  function getRawTextAndLocationEnd(val, offset, line, column,
519
509
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
520
510
  tokens, offsets, pug) {
521
- var _a;
522
511
  let beforeNewlineToken = null;
523
512
  for (const token of tokens) {
524
513
  // Searching token after the text.
@@ -528,7 +517,7 @@ tokens, offsets, pug) {
528
517
  token.type !== 'text-html' &&
529
518
  token.type !== 'indent' &&
530
519
  token.type !== 'outdent') {
531
- const endAttrLineOffset = Math.max((_a = offsets[beforeNewlineToken.loc.end.line - 2]) !== null && _a !== void 0 ? _a : 0, 0);
520
+ const endAttrLineOffset = Math.max(offsets[beforeNewlineToken.loc.end.line - 2] ?? 0, 0);
532
521
  const endAttrOffset = endAttrLineOffset + beforeNewlineToken.loc.end.column - 1;
533
522
  return {
534
523
  endOffset: endAttrOffset,
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getOffsetFromLineAndCol = void 0;
4
- function getOffsetFromLineAndCol(str, line, col) {
1
+ export function getOffsetFromLineAndCol(str, line, col) {
5
2
  const lines = str.split('\n').slice(0, line);
6
3
  const lastLine = lines.pop();
7
4
  if (lastLine) {
@@ -9,4 +6,3 @@ function getOffsetFromLineAndCol(str, line, col) {
9
6
  }
10
7
  return lines.join('\n').length;
11
8
  }
12
- exports.getOffsetFromLineAndCol = getOffsetFromLineAndCol;
package/package.json CHANGED
@@ -1,12 +1,17 @@
1
1
  {
2
2
  "name": "@markuplint/pug-parser",
3
- "version": "3.10.0",
3
+ "version": "4.0.0-alpha.2",
4
4
  "description": "Pug parser for markuplint",
5
5
  "repository": "git@github.com:markuplint/markuplint.git",
6
6
  "author": "Yusuke Hirao <yusukehirao@me.com>",
7
7
  "license": "MIT",
8
8
  "private": false,
9
- "main": "lib/index.js",
9
+ "type": "module",
10
+ "exports": {
11
+ ".": {
12
+ "import": "./lib/index.js"
13
+ }
14
+ },
10
15
  "types": "lib/index.d.ts",
11
16
  "publishConfig": {
12
17
  "access": "public"
@@ -16,12 +21,12 @@
16
21
  "clean": "tsc --build --clean"
17
22
  },
18
23
  "dependencies": {
19
- "@markuplint/html-parser": "3.11.0",
20
- "@markuplint/ml-ast": "3.2.0",
21
- "@markuplint/parser-utils": "3.11.0",
24
+ "@markuplint/html-parser": "4.0.0-alpha.2",
25
+ "@markuplint/ml-ast": "4.0.0-alpha.2",
26
+ "@markuplint/parser-utils": "4.0.0-alpha.2",
22
27
  "pug-lexer": "^5.0.1",
23
28
  "pug-parser": "^6.0.0",
24
29
  "tslib": "^2.6.2"
25
30
  },
26
- "gitHead": "ef31aef8f2fff319d0f692feead332ec5fc5c7cf"
31
+ "gitHead": "51ad52c760435641f9bff8685707d8178b0787eb"
27
32
  }