@markuplint/ml-core 4.0.0-alpha.6 → 4.0.0-alpha.8

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-2023 Yusuke Hirao
3
+ Copyright (c) 2017-2024 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
@@ -2141,9 +2141,6 @@ export class MLDocument extends MLParentNode {
2141
2141
  if (docLog.enabled) {
2142
2142
  docLog('Pretending: %O', pretenders);
2143
2143
  }
2144
- if (!pretenders) {
2145
- return;
2146
- }
2147
2144
  for (const node of this.nodeList) {
2148
2145
  if (node.is(node.ELEMENT_NODE)) {
2149
2146
  node.pretending(pretenders);
@@ -12,6 +12,13 @@ import { MLParentNode } from './parent-node.js';
12
12
  export declare class MLElement<T extends RuleConfigValue, O extends PlainData = undefined> extends MLParentNode<T, O, MLASTElement> implements Element, HTMLOrSVGElement, HTMLElement {
13
13
  #private;
14
14
  readonly closeTag: MLToken | null;
15
+ /**
16
+ * Element type
17
+ *
18
+ * - `html`: From native HTML Standard
19
+ * - `web-component`: As the Web Component according to HTML Standard
20
+ * - `authored`: Authored element (JSX Element etc.) through the view framework or the template engine.
21
+ */
15
22
  readonly elementType: ElementType;
16
23
  readonly endSpace: MLToken | null;
17
24
  readonly hasSpreadAttr: boolean;
@@ -1781,7 +1788,7 @@ export declare class MLElement<T extends RuleConfigValue, O extends PlainData =
1781
1788
  /**
1782
1789
  * Pretenders Initialization
1783
1790
  */
1784
- pretending(pretenders: readonly Pretender[]): void;
1791
+ pretending(pretenders?: readonly Pretender[]): void;
1785
1792
  /**
1786
1793
  * **IT THROWS AN ERROR WHEN CALLING THIS.**
1787
1794
  *
@@ -2454,24 +2454,32 @@ export class MLElement extends MLParentNode {
2454
2454
  */
2455
2455
  pretending(pretenders) {
2456
2456
  const pretenderConfig = pretenders?.find(option => this.matches(option.selector));
2457
- if (!pretenderConfig) {
2457
+ const asAttrValue = this.getAttribute('as');
2458
+ const pretenderElement = pretenderConfig?.as ??
2459
+ (this.elementType === 'html' || !asAttrValue
2460
+ ? null
2461
+ : {
2462
+ element: asAttrValue,
2463
+ inheritAttrs: true,
2464
+ });
2465
+ if (pretenderElement == null) {
2458
2466
  return;
2459
2467
  }
2460
2468
  let nodeName;
2461
2469
  let namespace = 'html';
2462
2470
  const attributes = [];
2463
2471
  let aria;
2464
- if (typeof pretenderConfig.as === 'string') {
2465
- nodeName = pretenderConfig.as;
2472
+ if (typeof pretenderElement === 'string') {
2473
+ nodeName = pretenderElement;
2466
2474
  }
2467
2475
  else {
2468
- nodeName = pretenderConfig.as.element;
2469
- namespace = pretenderConfig.as.namespace ?? namespace;
2470
- if (pretenderConfig.as.inheritAttrs) {
2476
+ nodeName = pretenderElement.element;
2477
+ namespace = pretenderElement.namespace ?? namespace;
2478
+ if (pretenderElement.inheritAttrs) {
2471
2479
  attributes.push(...this._astToken.attributes);
2472
2480
  }
2473
- if (pretenderConfig.as.attrs) {
2474
- attributes.push(...pretenderConfig.as.attrs.map(({ name, value }, i) => {
2481
+ if (pretenderElement.attrs) {
2482
+ attributes.push(...pretenderElement.attrs.map(({ name, value }, i) => {
2475
2483
  const _value = value == null
2476
2484
  ? ''
2477
2485
  : typeof value === 'string'
@@ -2523,7 +2531,7 @@ export class MLElement extends MLParentNode {
2523
2531
  };
2524
2532
  }));
2525
2533
  }
2526
- aria = pretenderConfig.as.aria;
2534
+ aria = pretenderElement.aria;
2527
2535
  }
2528
2536
  const as = new MLElement({
2529
2537
  ...this._astToken,
@@ -3,6 +3,9 @@ import type { Attr, Element } from '../ml-dom/index.js';
3
3
  import type { Translator } from '@markuplint/i18n';
4
4
  import type { PlainData, Report, RuleConfigValue, Severity } from '@markuplint/ml-config';
5
5
  export type RuleSeed<T extends RuleConfigValue = boolean, O extends PlainData = undefined> = {
6
+ readonly meta?: {
7
+ readonly category?: 'validation' | 'style' | 'naming-convention' | 'a11y' | 'maintainability';
8
+ };
6
9
  readonly defaultSeverity?: Severity;
7
10
  readonly defaultValue?: T;
8
11
  readonly defaultOptions?: O;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markuplint/ml-core",
3
- "version": "4.0.0-alpha.6",
3
+ "version": "4.0.0-alpha.8",
4
4
  "description": "The core module of markuplint",
5
5
  "repository": "git@github.com:markuplint/markuplint.git",
6
6
  "author": "Yusuke Hirao <yusukehirao@me.com>",
@@ -28,19 +28,19 @@
28
28
  "./lib/configs.js": "./lib/configs.browser.js"
29
29
  },
30
30
  "dependencies": {
31
- "@markuplint/config-presets": "4.0.0-alpha.6",
32
- "@markuplint/html-parser": "4.0.0-alpha.6",
33
- "@markuplint/html-spec": "4.0.0-alpha.6",
34
- "@markuplint/i18n": "4.0.0-alpha.6",
35
- "@markuplint/ml-ast": "4.0.0-alpha.6",
36
- "@markuplint/ml-config": "4.0.0-alpha.6",
37
- "@markuplint/ml-spec": "4.0.0-alpha.6",
38
- "@markuplint/parser-utils": "4.0.0-alpha.6",
39
- "@markuplint/selector": "4.0.0-alpha.6",
31
+ "@markuplint/config-presets": "4.0.0-alpha.8",
32
+ "@markuplint/html-parser": "4.0.0-alpha.8",
33
+ "@markuplint/html-spec": "4.0.0-alpha.8",
34
+ "@markuplint/i18n": "4.0.0-alpha.8",
35
+ "@markuplint/ml-ast": "4.0.0-alpha.8",
36
+ "@markuplint/ml-config": "4.0.0-alpha.8",
37
+ "@markuplint/ml-spec": "4.0.0-alpha.8",
38
+ "@markuplint/parser-utils": "4.0.0-alpha.8",
39
+ "@markuplint/selector": "4.0.0-alpha.8",
40
40
  "@types/debug": "^4.1.12",
41
41
  "debug": "^4.3.4",
42
42
  "is-plain-object": "^5.0.0",
43
- "type-fest": "^4.8.2"
43
+ "type-fest": "^4.9.0"
44
44
  },
45
- "gitHead": "06e1242d274c72cf08a10a572b06ac35d1b924a4"
45
+ "gitHead": "5bcd25f13ff804af0d09aaabd87e495af668e6a8"
46
46
  }