@markuplint/pug-parser 4.0.0-alpha.10 → 4.0.0-alpha.11

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/lib/parser.d.ts CHANGED
@@ -19,11 +19,7 @@ declare class PugParser extends Parser<ASTNode> {
19
19
  readonly attributes: readonly MLASTAttr[];
20
20
  };
21
21
  }): MLASTNodeTreeItem[];
22
- visitAttr(token: Token): (import("@markuplint/ml-ast").MLASTHTMLAttr & {
23
- __rightText?: string | undefined;
24
- }) | (import("@markuplint/ml-ast").MLASTSpreadAttr & {
25
- __rightText?: string | undefined;
26
- });
22
+ visitAttr(token: Token): MLASTAttr;
27
23
  }
28
24
  export declare const parser: PugParser;
29
25
  export {};
package/lib/parser.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { getNamespace, parser as htmlParser } from '@markuplint/html-parser';
2
- import { ParserError, Parser, AttrState, removeQuote, scriptParser } from '@markuplint/parser-utils';
2
+ import { ParserError, Parser, AttrState, scriptParser } from '@markuplint/parser-utils';
3
3
  import { pugParse } from './pug-parser/index.js';
4
4
  class PugParser extends Parser {
5
5
  constructor() {
@@ -143,20 +143,56 @@ class PugParser extends Parser {
143
143
  const valueCodeTokens = scriptParser(attr.value.raw.trim());
144
144
  if (valueCodeTokens.length === 1) {
145
145
  const token = valueCodeTokens[0];
146
- if (token.type === 'Numeric' || token.type === 'Boolean') {
147
- this.updateAttr(attr, { potentialValue: token.value });
148
- }
149
- else if (token.type === 'String' || token.type === 'Template') {
150
- this.updateAttr(attr, { potentialValue: removeQuote(token.value) });
151
- }
152
- else {
153
- this.updateAttr(attr, { isDynamicValue: true });
146
+ switch (token.type) {
147
+ case 'Numeric': {
148
+ return {
149
+ ...attr,
150
+ potentialValue: token.value,
151
+ valueType: 'number',
152
+ };
153
+ }
154
+ case 'Boolean': {
155
+ return {
156
+ ...attr,
157
+ potentialValue: token.value,
158
+ valueType: 'boolean',
159
+ };
160
+ }
161
+ case 'String':
162
+ case 'Template': {
163
+ const value = super.visitAttr(attr.value, {
164
+ startState: AttrState.BeforeValue,
165
+ quoteSet: [
166
+ { start: '"', end: '"' },
167
+ { start: "'", end: "'" },
168
+ { start: '`', end: '`' },
169
+ ],
170
+ quoteInValueChars: [
171
+ { start: '"', end: '"' },
172
+ { start: "'", end: "'" },
173
+ { start: '`', end: '`' },
174
+ { start: '${', end: '}' },
175
+ ],
176
+ });
177
+ if (value.type === 'spread') {
178
+ throw new ParserError('Unexpected attribute value', value);
179
+ }
180
+ return {
181
+ ...attr,
182
+ startQuote: value.startQuote,
183
+ value: value.value,
184
+ endQuote: value.endQuote,
185
+ potentialValue: value.value.raw,
186
+ valueType: 'string',
187
+ };
188
+ }
154
189
  }
155
190
  }
156
- else {
157
- this.updateAttr(attr, { isDynamicValue: true });
158
- }
159
- return attr;
191
+ return {
192
+ ...attr,
193
+ isDynamicValue: true,
194
+ valueType: 'code',
195
+ };
160
196
  }
161
197
  }
162
198
  export const parser = new PugParser();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markuplint/pug-parser",
3
- "version": "4.0.0-alpha.10",
3
+ "version": "4.0.0-alpha.11",
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.10",
25
- "@markuplint/ml-ast": "4.0.0-alpha.10",
26
- "@markuplint/parser-utils": "4.0.0-alpha.10",
24
+ "@markuplint/html-parser": "4.0.0-alpha.11",
25
+ "@markuplint/ml-ast": "4.0.0-alpha.11",
26
+ "@markuplint/parser-utils": "4.0.0-alpha.11",
27
27
  "pug-lexer": "^5.0.1",
28
28
  "pug-parser": "^6.0.0"
29
29
  },
30
- "gitHead": "b41153ea665aa8f091daf6114a06047f4ccb8350"
30
+ "gitHead": "78ab1adaa4e178b4187f6c5f135bb8fc0c8f4b9e"
31
31
  }