@markuplint/parser-utils 1.6.1 → 2.0.0-dev.23

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.
@@ -0,0 +1,405 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.searchIDLAttribute = void 0;
4
+ /**
5
+ * IDL attributes VS Content attributes
6
+ */
7
+ const idlContentMap = {
8
+ // HTML
9
+ accept: 'accept',
10
+ acceptCharset: 'acceptcharset',
11
+ accessKey: 'accesskey',
12
+ action: 'action',
13
+ allowFullScreen: 'allowfullscreen',
14
+ alt: 'alt',
15
+ as: 'as',
16
+ async: 'async',
17
+ autoCapitalize: 'autocapitalize',
18
+ autoComplete: 'autocomplete',
19
+ autoCorrect: 'autocorrect',
20
+ autoFocus: 'autofocus',
21
+ autoPlay: 'autoplay',
22
+ autoSave: 'autosave',
23
+ capture: 'capture',
24
+ cellPadding: 'cellpadding',
25
+ cellSpacing: 'cellspacing',
26
+ challenge: 'challenge',
27
+ charSet: 'charset',
28
+ checked: 'checked',
29
+ cite: 'cite',
30
+ classID: 'classid',
31
+ className: 'class',
32
+ cols: 'cols',
33
+ colSpan: 'colspan',
34
+ content: 'content',
35
+ contentEditable: 'contenteditable',
36
+ contextMenu: 'contextmenu',
37
+ controls: 'controls',
38
+ controlsList: 'controlslist',
39
+ coords: 'coords',
40
+ crossOrigin: 'crossorigin',
41
+ data: 'data',
42
+ dateTime: 'datetime',
43
+ default: 'default',
44
+ defer: 'defer',
45
+ dir: 'dir',
46
+ disabled: 'disabled',
47
+ disablePictureInPicture: 'disablepictureinpicture',
48
+ disableRemotePlayback: 'disableremoteplayback',
49
+ download: 'download',
50
+ draggable: 'draggable',
51
+ encType: 'enctype',
52
+ enterKeyHint: 'enterkeyhint',
53
+ form: 'form',
54
+ formAction: 'formaction',
55
+ formEncType: 'formenctype',
56
+ formMethod: 'formmethod',
57
+ formNoValidate: 'formnovalidate',
58
+ formTarget: 'formtarget',
59
+ frameBorder: 'frameborder',
60
+ headers: 'headers',
61
+ height: 'height',
62
+ hidden: 'hidden',
63
+ high: 'high',
64
+ href: 'href',
65
+ hrefLang: 'hreflang',
66
+ htmlFor: 'for',
67
+ httpEquiv: 'httpequiv',
68
+ icon: 'icon',
69
+ id: 'id',
70
+ inputMode: 'inputmode',
71
+ integrity: 'integrity',
72
+ is: 'is',
73
+ itemID: 'itemid',
74
+ itemProp: 'itemprop',
75
+ itemRef: 'itemref',
76
+ itemScope: 'itemscope',
77
+ itemType: 'itemtype',
78
+ keyParams: 'keyparams',
79
+ keyType: 'keytype',
80
+ kind: 'kind',
81
+ label: 'label',
82
+ lang: 'lang',
83
+ list: 'list',
84
+ loop: 'loop',
85
+ low: 'low',
86
+ manifest: 'manifest',
87
+ marginHeight: 'marginheight',
88
+ marginWidth: 'marginwidth',
89
+ max: 'max',
90
+ maxLength: 'maxlength',
91
+ media: 'media',
92
+ mediaGroup: 'mediagroup',
93
+ method: 'method',
94
+ min: 'min',
95
+ minLength: 'minlength',
96
+ multiple: 'multiple',
97
+ muted: 'muted',
98
+ name: 'name',
99
+ noModule: 'nomodule',
100
+ nonce: 'nonce',
101
+ noValidate: 'novalidate',
102
+ open: 'open',
103
+ optimum: 'optimum',
104
+ pattern: 'pattern',
105
+ placeholder: 'placeholder',
106
+ playsInline: 'playsinline',
107
+ poster: 'poster',
108
+ preload: 'preload',
109
+ profile: 'profile',
110
+ radioGroup: 'radiogroup',
111
+ readOnly: 'readonly',
112
+ referrerPolicy: 'referrerpolicy',
113
+ rel: 'rel',
114
+ required: 'required',
115
+ reversed: 'reversed',
116
+ role: 'role',
117
+ rows: 'rows',
118
+ rowSpan: 'rowspan',
119
+ sandbox: 'sandbox',
120
+ scope: 'scope',
121
+ scoped: 'scoped',
122
+ scrolling: 'scrolling',
123
+ seamless: 'seamless',
124
+ selected: 'selected',
125
+ shape: 'shape',
126
+ size: 'size',
127
+ sizes: 'sizes',
128
+ span: 'span',
129
+ spellCheck: 'spellcheck',
130
+ src: 'src',
131
+ srcDoc: 'srcdoc',
132
+ srcLang: 'srclang',
133
+ srcSet: 'srcset',
134
+ start: 'start',
135
+ step: 'step',
136
+ style: 'style',
137
+ summary: 'summary',
138
+ tabIndex: 'tabindex',
139
+ target: 'target',
140
+ title: 'title',
141
+ type: 'type',
142
+ useMap: 'usemap',
143
+ value: 'value',
144
+ width: 'width',
145
+ wmode: 'wmode',
146
+ wrap: 'wrap',
147
+ // SVG
148
+ accentHeight: 'accent-height',
149
+ accumulate: 'accumulate',
150
+ additive: 'additive',
151
+ alignmentBaseline: 'alignment-baseline',
152
+ alphabetic: 'alphabetic',
153
+ amplitude: 'amplitude',
154
+ arabicForm: 'arabic-form',
155
+ ascent: 'ascent',
156
+ attributeName: 'attributeName',
157
+ attributeType: 'attributeType',
158
+ azimuth: 'azimuth',
159
+ baseFrequency: 'baseFrequency',
160
+ baselineShift: 'baseline-shift',
161
+ baseProfile: 'baseProfile',
162
+ bbox: 'bbox',
163
+ begin: 'begin',
164
+ bias: 'bias',
165
+ by: 'by',
166
+ calcMode: 'calcMode',
167
+ capHeight: 'cap-height',
168
+ clip: 'clip',
169
+ clipPath: 'clipPathUnits',
170
+ clipPathUnits: 'clip-path',
171
+ clipRule: 'clip-rule',
172
+ color: 'color',
173
+ colorInterpolation: 'color-interpolation',
174
+ colorInterpolationFilters: 'color-interpolation-filters',
175
+ colorProfile: 'color-profile',
176
+ colorRendering: 'color-rendering',
177
+ contentScriptType: 'contentScriptType',
178
+ contentStyleType: 'contentStyleType',
179
+ cursor: 'cursor',
180
+ cx: 'cx',
181
+ cy: 'cy',
182
+ d: 'd',
183
+ decelerate: 'decelerate',
184
+ descent: 'descent',
185
+ diffuseConstant: 'diffuseConstant',
186
+ direction: 'direction',
187
+ display: 'display',
188
+ divisor: 'divisor',
189
+ dominantBaseline: 'dominant-baseline',
190
+ dur: 'dur',
191
+ dx: 'dx',
192
+ dy: 'dy',
193
+ edgeMode: 'edgeMode',
194
+ elevation: 'elevation',
195
+ enableBackground: 'enable-background',
196
+ end: 'end',
197
+ exponent: 'exponent',
198
+ fill: 'fill',
199
+ fillOpacity: 'fill-opacity',
200
+ fillRule: 'fill-rule',
201
+ filter: 'filter',
202
+ filterRes: 'filterRes',
203
+ filterUnits: 'filterUnits',
204
+ floodColor: 'flood-color',
205
+ floodOpacity: 'flood-opacity',
206
+ focusable: 'focusable',
207
+ fontFamily: 'font-family',
208
+ fontSize: 'font-size',
209
+ fontSizeAdjust: 'font-size-adjust',
210
+ fontStretch: 'font-stretch',
211
+ fontStyle: 'font-style',
212
+ fontVariant: 'font-variant',
213
+ fontWeight: 'font-weight',
214
+ format: 'format',
215
+ from: 'from',
216
+ fr: 'fr',
217
+ fx: 'fx',
218
+ fy: 'fy',
219
+ g1: 'g1',
220
+ g2: 'g2',
221
+ glyphName: 'glyph-name',
222
+ glyphOrientationHorizontal: 'glyph-orientation-horizontal',
223
+ glyphOrientationVertical: 'glyph-orientation-vertical',
224
+ glyphRef: 'glyphRef',
225
+ gradientTransform: 'gradientTransform',
226
+ gradientUnits: 'gradientUnits',
227
+ hanging: 'hanging',
228
+ horizAdvX: 'horiz-adv-x',
229
+ horizOriginX: 'horiz-origin-x',
230
+ ideographic: 'ideographic',
231
+ imageRendering: 'image-rendering',
232
+ in: 'in',
233
+ in2: 'in2',
234
+ intercept: 'intercept',
235
+ k: 'k',
236
+ k1: 'k1',
237
+ k2: 'k2',
238
+ k3: 'k3',
239
+ k4: 'k4',
240
+ kernelMatrix: 'kernelMatrix',
241
+ kernelUnitLength: 'kernelUnitLength',
242
+ kerning: 'kerning',
243
+ keyPoints: 'keyPoints',
244
+ keySplines: 'keySplines',
245
+ keyTimes: 'keyTimes',
246
+ lengthAdjust: 'lengthAdjust',
247
+ letterSpacing: 'letter-spacing',
248
+ lightingColor: 'lighting-color',
249
+ limitingConeAngle: 'limitingConeAngle',
250
+ local: 'local',
251
+ markerEnd: 'marker-end',
252
+ markerHeight: 'markerHeight',
253
+ markerMid: 'marker-mid',
254
+ markerStart: 'marker-start',
255
+ markerUnits: 'markerUnits',
256
+ markerWidth: 'markerWidth',
257
+ mask: 'mask',
258
+ maskContentUnits: 'maskContentUnits',
259
+ maskUnits: 'maskUnits',
260
+ mathematical: 'mathematical',
261
+ mode: 'mode',
262
+ numOctaves: 'numOctaves',
263
+ offset: 'offset',
264
+ opacity: 'opacity',
265
+ operator: 'operator',
266
+ order: 'order',
267
+ orient: 'orient',
268
+ orientation: 'orientation',
269
+ origin: 'origin',
270
+ overflow: 'overflow',
271
+ overlinePosition: 'overline-position',
272
+ overlineThickness: 'overline-thickness',
273
+ paintOrder: 'paint-order',
274
+ panose1: 'panose-1',
275
+ pathLength: 'pathLength',
276
+ patternContentUnits: 'patternContentUnits',
277
+ patternTransform: 'patternTransform',
278
+ patternUnits: 'patternUnits',
279
+ pointerEvents: 'pointer-events',
280
+ points: 'points',
281
+ pointsAtX: 'pointsAtX',
282
+ pointsAtY: 'pointsAtY',
283
+ pointsAtZ: 'pointsAtZ',
284
+ preserveAlpha: 'preserveAlpha',
285
+ preserveAspectRatio: 'preserveAspectRatio',
286
+ primitiveUnits: 'primitiveUnits',
287
+ r: 'r',
288
+ refX: 'refX',
289
+ refY: 'refY',
290
+ renderingIntent: 'rendering-intent',
291
+ repeatCount: 'repeatCount',
292
+ repeatDur: 'repeatDur',
293
+ requiredExtensions: 'requiredExtensions',
294
+ requiredFeatures: 'requiredFeatures',
295
+ restart: 'restart',
296
+ result: 'result',
297
+ rotate: 'rotate',
298
+ rx: 'rx',
299
+ ry: 'ry',
300
+ scale: 'scale',
301
+ seed: 'seed',
302
+ shapeRendering: 'shape-rendering',
303
+ slope: 'slope',
304
+ spacing: 'spacing',
305
+ specularConstant: 'specularConstant',
306
+ specularExponent: 'specularExponent',
307
+ speed: 'speed',
308
+ spreadMethod: 'spreadMethod',
309
+ startOffset: 'startOffset',
310
+ stdDeviation: 'stdDeviation',
311
+ stemh: 'stemh',
312
+ stemv: 'stemv',
313
+ stitchTiles: 'stitchTiles',
314
+ stopColor: 'stop-color',
315
+ stopOpacity: 'stop-opacity',
316
+ strikethroughPosition: 'strikethrough-position',
317
+ strikethroughThickness: 'strikethrough-thickness',
318
+ string: 'string',
319
+ stroke: 'stroke',
320
+ strokeDasharray: 'stroke-dasharray',
321
+ strokeDashoffset: 'stroke-dashoffset',
322
+ strokeLinecap: 'stroke-linecap',
323
+ strokeLinejoin: 'stroke-linejoin',
324
+ strokeMiterlimit: 'stroke-miterlimit',
325
+ strokeOpacity: 'stroke-opacity',
326
+ strokeWidth: 'stroke-width',
327
+ surfaceScale: 'surfaceScale',
328
+ systemLanguage: 'systemLanguage',
329
+ tableValues: 'tableValues',
330
+ targetX: 'targetX',
331
+ targetY: 'targetY',
332
+ textAnchor: 'text-anchor',
333
+ textDecoration: 'text-decoration',
334
+ textLength: 'textLength',
335
+ textRendering: 'text-rendering',
336
+ to: 'to',
337
+ transform: 'transform',
338
+ transformOrigin: 'transform-origin',
339
+ u1: 'u1',
340
+ u2: 'u2',
341
+ underlinePosition: 'underline-position',
342
+ underlineThickness: 'underline-thickness',
343
+ unicode: 'unicode',
344
+ unicodeBidi: 'unicode-bidi',
345
+ unicodeRange: 'unicode-range',
346
+ unitsPerEm: 'units-per-em',
347
+ vAlphabetic: 'v-alphabetic',
348
+ values: 'values',
349
+ vectorEffect: 'vector-effect',
350
+ version: 'version',
351
+ vertAdvY: 'vert-adv-y',
352
+ vertOriginX: 'vert-origin-x',
353
+ vertOriginY: 'vert-origin-y',
354
+ vHanging: 'v-hanging',
355
+ vIdeographic: 'v-ideographic',
356
+ viewBox: 'viewBox',
357
+ viewTarget: 'viewTarget',
358
+ visibility: 'visibility',
359
+ vMathematical: 'v-mathematical',
360
+ widths: 'widths',
361
+ wordSpacing: 'word-spacing',
362
+ writingMode: 'writing-mode',
363
+ x: 'x',
364
+ x1: 'x1',
365
+ x2: 'x2',
366
+ xChannelSelector: 'xChannelSelector',
367
+ xHeight: 'x-height',
368
+ xlinkActuate: 'xlink:actuate',
369
+ xlinkArcrole: 'xlink:arcrole',
370
+ xlinkHref: 'xlink:href',
371
+ xlinkRole: 'xlink:role',
372
+ xlinkShow: 'xlink:show',
373
+ xlinkTitle: 'xlink:title',
374
+ xlinkType: 'xlink:type',
375
+ xmlBase: 'xml:base',
376
+ xmlLang: 'xml:lang',
377
+ xmlnsXlink: 'xmlns:xlink',
378
+ xmlSpace: 'xml:space',
379
+ y: 'y',
380
+ y1: 'y1',
381
+ y2: 'y1',
382
+ yChannelSelector: 'yChannelSelector',
383
+ z: 'z',
384
+ zoomAndPan: 'zoomAndPan',
385
+ };
386
+ const list = Object.entries(idlContentMap);
387
+ function searchIDLAttribute(name) {
388
+ const camelizedName = camelize(name);
389
+ const [idlPropName, contentAttrName] = (/^on[a-z]/.test(name) && [name.toLowerCase(), name.toLowerCase()]) ||
390
+ list.find(([idlPropName, contentAttrName]) => idlPropName.toLowerCase() === camelizedName.toLowerCase() ||
391
+ contentAttrName.toLowerCase() === name.toLowerCase() ||
392
+ hyphenize(idlPropName) === name.toLowerCase()) ||
393
+ [];
394
+ return {
395
+ idlPropName,
396
+ contentAttrName,
397
+ };
398
+ }
399
+ exports.searchIDLAttribute = searchIDLAttribute;
400
+ function camelize(str) {
401
+ return str.replace(/[:-][a-z]/g, $0 => $0[1].toUpperCase());
402
+ }
403
+ function hyphenize(str) {
404
+ return str.replace(/[A-Z]/g, $0 => `-${$0.toLowerCase()}`);
405
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const idl_attributes_1 = require("./idl-attributes");
4
+ it('basic', () => {
5
+ expect((0, idl_attributes_1.searchIDLAttribute)('class')).toStrictEqual({
6
+ idlPropName: 'className',
7
+ contentAttrName: 'class',
8
+ });
9
+ expect((0, idl_attributes_1.searchIDLAttribute)('for')).toStrictEqual({
10
+ idlPropName: 'htmlFor',
11
+ contentAttrName: 'for',
12
+ });
13
+ expect((0, idl_attributes_1.searchIDLAttribute)('className')).toStrictEqual({
14
+ idlPropName: 'className',
15
+ contentAttrName: 'class',
16
+ });
17
+ expect((0, idl_attributes_1.searchIDLAttribute)('htmlFor')).toStrictEqual({
18
+ idlPropName: 'htmlFor',
19
+ contentAttrName: 'for',
20
+ });
21
+ expect((0, idl_attributes_1.searchIDLAttribute)('tabindex')).toStrictEqual({
22
+ idlPropName: 'tabIndex',
23
+ contentAttrName: 'tabindex',
24
+ });
25
+ expect((0, idl_attributes_1.searchIDLAttribute)('tab-index')).toStrictEqual({
26
+ idlPropName: 'tabIndex',
27
+ contentAttrName: 'tabindex',
28
+ });
29
+ expect((0, idl_attributes_1.searchIDLAttribute)('TabIndex')).toStrictEqual({
30
+ idlPropName: 'tabIndex',
31
+ contentAttrName: 'tabindex',
32
+ });
33
+ expect((0, idl_attributes_1.searchIDLAttribute)('x')).toStrictEqual({
34
+ idlPropName: 'x',
35
+ contentAttrName: 'x',
36
+ });
37
+ expect((0, idl_attributes_1.searchIDLAttribute)('y')).toStrictEqual({
38
+ idlPropName: 'y',
39
+ contentAttrName: 'y',
40
+ });
41
+ expect((0, idl_attributes_1.searchIDLAttribute)('attribute-name')).toStrictEqual({
42
+ idlPropName: 'attributeName',
43
+ contentAttrName: 'attributeName',
44
+ });
45
+ });
@@ -1,4 +1,4 @@
1
- import { IgnoreBlock, IgnoreTag } from './types';
2
- import { MLASTNode } from '@markuplint/ml-ast';
1
+ import type { IgnoreBlock, IgnoreTag } from './types';
2
+ import type { MLASTNode } from '@markuplint/ml-ast';
3
3
  export declare function ignoreBlock(source: string, tags: IgnoreTag[]): IgnoreBlock;
4
4
  export declare function restoreNode(nodeList: MLASTNode[], ignoreBlock: IgnoreBlock): MLASTNode[];
@@ -1,39 +1,35 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.restoreNode = exports.ignoreBlock = void 0;
4
- const ml_ast_1 = require("@markuplint/ml-ast");
5
- const utils_1 = require("./utils");
6
4
  const const_1 = require("./const");
5
+ const create_token_1 = require("./create-token");
6
+ const get_location_1 = require("./get-location");
7
+ const siblings_correction_1 = require("./siblings-correction");
7
8
  function ignoreBlock(source, tags) {
8
9
  let replaced = source;
9
10
  const stack = [];
10
11
  for (const tag of tags) {
11
- const start = removeGlobalOption(tag.start);
12
- const end = removeGlobalOption(tag.end);
13
- while (start.test(replaced)) {
14
- const [index, above, startTag, _below] = snap(replaced, start);
15
- if (!startTag || !_below) {
16
- continue;
17
- }
18
- const [, taggedCode, endTag, below] = snap(_below, end);
19
- stack.push({
20
- type: tag.type,
21
- index,
22
- startTag,
23
- taggedCode,
24
- endTag: endTag || null,
25
- });
26
- /**
27
- * It will not replace line breaks because detects line number.
28
- */
12
+ // Replace tags in attributes
13
+ const attr = maskText(prepend(tag.start, '(?<=(?:"|\'))'), append(tag.end, '(?=(?:"|\'))'), replaced, (startTag, taggedCode, endTag) => {
14
+ const mask = const_1.MASK_CHAR.repeat(startTag.length) +
15
+ taggedCode.replace(/[^\n]/g, const_1.MASK_CHAR) +
16
+ const_1.MASK_CHAR.repeat((endTag || '').length);
17
+ return mask;
18
+ });
19
+ replaced = attr.replaced;
20
+ stack.push(...attr.stack.map(res => ({ ...res, type: tag.type })));
21
+ // Replace tags in other nodes
22
+ const text = maskText(tag.start, tag.end, replaced, (startTag, taggedCode, endTag) => {
29
23
  const mask = const_1.MASK_CHAR.repeat(startTag.length) +
30
24
  taggedCode.replace(/[^\n]/g, const_1.MASK_CHAR) +
31
25
  const_1.MASK_CHAR.repeat((endTag || '').length);
32
26
  const taggedMask = `<!${mask.slice(2).slice(0, -1)}>`;
33
- replaced = above + taggedMask + (below || '');
34
- }
35
- stack.sort((a, b) => a.index - b.index);
27
+ return taggedMask;
28
+ });
29
+ replaced = text.replaced;
30
+ stack.push(...text.stack.map(res => ({ ...res, type: tag.type })));
36
31
  }
32
+ stack.sort((a, b) => a.index - b.index);
37
33
  return {
38
34
  source,
39
35
  replaced,
@@ -41,11 +37,37 @@ function ignoreBlock(source, tags) {
41
37
  };
42
38
  }
43
39
  exports.ignoreBlock = ignoreBlock;
40
+ function maskText(start, end, replaced, masking) {
41
+ const stack = [];
42
+ start = removeGlobalOption(start);
43
+ end = removeGlobalOption(end);
44
+ while (start.test(replaced)) {
45
+ const [index, above, startTag, _below] = snap(replaced, start);
46
+ if (!startTag || !_below) {
47
+ continue;
48
+ }
49
+ const [, taggedCode, endTag, below] = snap(_below, end);
50
+ stack.push({
51
+ index,
52
+ startTag,
53
+ taggedCode,
54
+ endTag: endTag || null,
55
+ });
56
+ /**
57
+ * It will not replace line breaks because detects line number.
58
+ */
59
+ replaced = above + masking(startTag, taggedCode, endTag) + (below || '');
60
+ }
61
+ return {
62
+ replaced,
63
+ stack,
64
+ };
65
+ }
44
66
  function restoreNode(nodeList, ignoreBlock) {
45
67
  nodeList = nodeList.slice();
46
68
  const { source, stack } = ignoreBlock;
47
69
  for (const node of nodeList) {
48
- if (node.type === ml_ast_1.MLASTNodeType.Comment) {
70
+ if (node.type === 'comment' || node.type === 'text') {
49
71
  if (!hasIgnoreBlock(node.raw)) {
50
72
  continue;
51
73
  }
@@ -62,22 +84,27 @@ function restoreNode(nodeList, ignoreBlock) {
62
84
  const below = text.slice(above.length + body.length);
63
85
  if (above) {
64
86
  const offset = node.startOffset + pointer;
65
- const { raw, startOffset, endOffset, startLine, endLine, startCol, endCol } = utils_1.sliceFragment(source, offset, offset + above.length);
66
- const textNode = Object.assign(Object.assign({}, node), { uuid: utils_1.uuid(), type: ml_ast_1.MLASTNodeType.Text, raw,
87
+ const { raw, startOffset, endOffset, startLine, endLine, startCol, endCol } = (0, get_location_1.sliceFragment)(source, offset, offset + above.length);
88
+ const textNode = {
89
+ ...node,
90
+ uuid: (0, create_token_1.uuid)(),
91
+ type: 'text',
92
+ raw,
67
93
  startOffset,
68
94
  endOffset,
69
95
  startLine,
70
96
  endLine,
71
97
  startCol,
72
- endCol });
98
+ endCol,
99
+ };
73
100
  insertList.push(textNode);
74
101
  }
75
102
  if (body) {
76
103
  const offset = node.startOffset + pointer + above.length;
77
- const { raw, startOffset, endOffset, startLine, endLine, startCol, endCol } = utils_1.sliceFragment(source, offset, offset + body.length);
104
+ const { raw, startOffset, endOffset, startLine, endLine, startCol, endCol } = (0, get_location_1.sliceFragment)(source, offset, offset + body.length);
78
105
  const bodyNode = {
79
- uuid: utils_1.uuid(),
80
- type: ml_ast_1.MLASTNodeType.PreprocessorSpecificBlock,
106
+ uuid: (0, create_token_1.uuid)(),
107
+ type: 'psblock',
81
108
  nodeName: `#ps:${tag.type}`,
82
109
  raw,
83
110
  parentNode: node.parentNode,
@@ -100,22 +127,40 @@ function restoreNode(nodeList, ignoreBlock) {
100
127
  }
101
128
  if (text) {
102
129
  const offset = node.endOffset - text.length;
103
- const { raw, startOffset, endOffset, startLine, endLine, startCol, endCol } = utils_1.sliceFragment(source, offset, offset + text.length);
104
- const textNode = Object.assign(Object.assign({}, node), { uuid: utils_1.uuid(), type: ml_ast_1.MLASTNodeType.Text, raw,
130
+ const { raw, startOffset, endOffset, startLine, endLine, startCol, endCol } = (0, get_location_1.sliceFragment)(source, offset, offset + text.length);
131
+ const textNode = {
132
+ ...node,
133
+ uuid: (0, create_token_1.uuid)(),
134
+ type: 'text',
135
+ raw,
105
136
  startOffset,
106
137
  endOffset,
107
138
  startLine,
108
139
  endLine,
109
140
  startCol,
110
- endCol });
141
+ endCol,
142
+ };
111
143
  insertList.push(textNode);
112
144
  }
113
- utils_1.siblingsCorrection(insertList);
145
+ (0, siblings_correction_1.siblingsCorrection)(insertList);
114
146
  if (parentNode) {
115
147
  parentNode.childNodes = insertList;
116
148
  }
117
149
  nodeList.splice(index, 1, ...insertList);
118
150
  }
151
+ if (node.type === 'starttag') {
152
+ for (const attr of node.attributes) {
153
+ if (attr.type === 'ps-attr' || attr.value.raw === '' || !hasIgnoreBlock(attr.value.raw)) {
154
+ continue;
155
+ }
156
+ for (const tag of stack) {
157
+ if (attr.value.startOffset <= tag.index && tag.index < attr.value.endOffset) {
158
+ attr.value.raw = tag.startTag + tag.taggedCode + tag.endTag;
159
+ attr.isDynamicValue = true;
160
+ }
161
+ }
162
+ }
163
+ }
119
164
  }
120
165
  return nodeList;
121
166
  }
@@ -134,6 +179,12 @@ function snap(str, reg) {
134
179
  function removeGlobalOption(reg) {
135
180
  return new RegExp(reg.source, reg.ignoreCase ? 'i' : '');
136
181
  }
182
+ function prepend(reg, str) {
183
+ return new RegExp(str + reg.source, reg.ignoreCase ? 'i' : '');
184
+ }
185
+ function append(reg, str) {
186
+ return new RegExp(reg.source + str, reg.ignoreCase ? 'i' : '');
187
+ }
137
188
  function hasIgnoreBlock(textContent) {
138
189
  return textContent.includes(const_1.MASK_CHAR);
139
190
  }
@@ -0,0 +1 @@
1
+ export declare function ignoreFrontMatter(code: string): string;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ignoreFrontMatter = void 0;
4
+ function ignoreFrontMatter(code) {
5
+ const reStart = /^(?:\s*\r?\n)?---\r?\n/.exec(code);
6
+ if (!reStart) {
7
+ return code;
8
+ }
9
+ const startPoint = reStart[0].length;
10
+ const afterStart = code.slice(startPoint);
11
+ const reEnd = /\r?\n---\r?\n/.exec(afterStart);
12
+ if (!reEnd) {
13
+ return code;
14
+ }
15
+ const endPoint = startPoint + reEnd.index + reEnd[0].length;
16
+ const frontMatter = code.slice(0, endPoint);
17
+ const afterCode = code.slice(endPoint);
18
+ const masked = frontMatter.replace(/[^\r\n]/g, ' ');
19
+ return masked + afterCode;
20
+ }
21
+ exports.ignoreFrontMatter = ignoreFrontMatter;
package/lib/index.d.ts CHANGED
@@ -1,3 +1,8 @@
1
+ export * from './decision';
2
+ export * from './get-location';
3
+ export * from './create-token';
4
+ export * from './idl-attributes';
5
+ export * from './walker';
1
6
  export * from './ignore-block';
2
- export * from './utils';
3
- export declare function ignoreFrontMatter(code: string): string;
7
+ export * from './ignore-front-matter';
8
+ export * from './debugger';