@markuplint/pug-parser 4.0.0-alpha.4 → 4.0.0-alpha.6

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2017-2019 Yusuke Hirao
3
+ Copyright (c) 2017-2023 Yusuke Hirao
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -1,3 +1,3 @@
1
1
  import type { ASTAttr } from './pug-parser/index.js';
2
2
  import type { MLASTAttr } from '@markuplint/ml-ast';
3
- export default function attrTokenizer(attr: ASTAttr): MLASTAttr;
3
+ export declare function attrTokenizer(attr: ASTAttr): MLASTAttr;
@@ -1,15 +1,10 @@
1
- import { tokenizer, uuid } from '@markuplint/parser-utils';
2
- export default function attrTokenizer(
1
+ import { tokenizer, uuid, scriptParser, removeQuote } from '@markuplint/parser-utils';
2
+ export function attrTokenizer(
3
3
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
4
4
  attr) {
5
5
  if (attr.raw[0] === '#' || attr.raw[0] === '.') {
6
- let value = '';
7
- if (typeof attr.val === 'string') {
8
- value = attr.val.match(/(["'`]?)([^\1]+)(\1)/)?.[2] ?? '';
9
- }
10
- else {
11
- value = `${attr.val}`;
12
- }
6
+ const value = `${attr.val}`;
7
+ const potentialValue = removeQuote(value);
13
8
  return {
14
9
  type: 'ps-attr',
15
10
  uuid: uuid(),
@@ -21,7 +16,7 @@ attr) {
21
16
  startCol: attr.column,
22
17
  endCol: attr.endColumn,
23
18
  potentialName: attr.name,
24
- potentialValue: value ?? '',
19
+ potentialValue,
25
20
  valueType: 'string',
26
21
  isDuplicatable: attr.raw[0] === '.',
27
22
  nodeName: '#pug-special-attr',
@@ -37,28 +32,29 @@ attr) {
37
32
  let spacesBeforeEqualChars;
38
33
  let equalChars;
39
34
  let spacesAfterEqualChars;
40
- let quoteChars;
35
+ const quoteChars = '';
41
36
  let valueChars;
37
+ let potentialValue;
42
38
  let isDynamicValue = undefined;
43
39
  if (attr.val === true) {
44
40
  spacesBeforeEqualChars = '';
45
41
  equalChars = '';
46
42
  spacesAfterEqualChars = '';
47
- quoteChars = '';
48
43
  valueChars = '';
44
+ potentialValue = '';
49
45
  }
50
46
  else {
51
47
  const withoutName = attr.raw.slice(attr.name.length);
52
48
  const valueOffset = withoutName.indexOf(attr.val);
53
49
  const equalAndBeforeSpaceAfterSpace = withoutName.slice(0, valueOffset);
54
50
  const [, before, equal, after] = equalAndBeforeSpaceAfterSpace.match(/^(\s*)(=)(\s*)$/) ?? ['', '', '', ''];
55
- const [, quote, coreValue] = attr.val.match(/(["'`]?)([^\1]+)(\1)/) ?? ['', '', ''];
51
+ const valueTokens = scriptParser(attr.val);
56
52
  spacesBeforeEqualChars = before ?? '';
57
53
  equalChars = equal ?? '';
58
54
  spacesAfterEqualChars = after ?? '';
59
- quoteChars = quote ?? '';
60
- valueChars = coreValue ?? '';
61
- if (quote === '`' || quote === '') {
55
+ valueChars = attr.val;
56
+ potentialValue = removeQuote(attr.val);
57
+ if (valueTokens.length > 1 || valueTokens[0].type !== 'String') {
62
58
  isDynamicValue = true;
63
59
  }
64
60
  }
@@ -127,6 +123,7 @@ attr) {
127
123
  endQuote,
128
124
  isDynamicValue,
129
125
  isDuplicatable,
126
+ potentialValue,
130
127
  nodeName: name.raw,
131
128
  parentNode: null,
132
129
  nextNode: null,
package/lib/parse.js CHANGED
@@ -12,7 +12,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
12
12
  var _Parser_ast;
13
13
  import { getNamespace, parse as htmlParse, isDocumentFragment } from '@markuplint/html-parser';
14
14
  import { detectElementType, ignoreFrontMatter, ParserError, tokenizer, uuid, walk, removeDeprecatedNode, } from '@markuplint/parser-utils';
15
- import attrTokenizer from './attr-tokenizer.js';
15
+ import { attrTokenizer } from './attr-tokenizer.js';
16
16
  import { pugParse } from './pug-parser/index.js';
17
17
  export const parse = (rawCode, options) => {
18
18
  let unknownParseError;
@@ -13,7 +13,7 @@ export function pugParse(pug) {
13
13
  return ast;
14
14
  }
15
15
  function getOffsetsFromLines(pug) {
16
- const lines = pug.split(/\n/g);
16
+ const lines = pug.split(/\n/);
17
17
  let chars = 0;
18
18
  const result = lines.map(line => {
19
19
  chars += line.length + 1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markuplint/pug-parser",
3
- "version": "4.0.0-alpha.4",
3
+ "version": "4.0.0-alpha.6",
4
4
  "description": "Pug parser for markuplint",
5
5
  "repository": "git@github.com:markuplint/markuplint.git",
6
6
  "author": "Yusuke Hirao <yusukehirao@me.com>",
@@ -21,11 +21,11 @@
21
21
  "clean": "tsc --build --clean"
22
22
  },
23
23
  "dependencies": {
24
- "@markuplint/html-parser": "4.0.0-alpha.4",
25
- "@markuplint/ml-ast": "4.0.0-alpha.4",
26
- "@markuplint/parser-utils": "4.0.0-alpha.4",
24
+ "@markuplint/html-parser": "4.0.0-alpha.6",
25
+ "@markuplint/ml-ast": "4.0.0-alpha.6",
26
+ "@markuplint/parser-utils": "4.0.0-alpha.6",
27
27
  "pug-lexer": "^5.0.1",
28
28
  "pug-parser": "^6.0.0"
29
29
  },
30
- "gitHead": "991b3aef77fde42c79343ee8c807257a35c589d7"
30
+ "gitHead": "06e1242d274c72cf08a10a572b06ac35d1b924a4"
31
31
  }