@wdprlib/parser 5.1.4 → 5.1.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.
@@ -19,13 +19,19 @@ export function consumeAttributeName(
19
19
  startName: string,
20
20
  options: AttributeNameOptions,
21
21
  ): AttributeNameResult {
22
+ if (startName === "_" && isAttributeWordToken(ctx.tokens[startPos])) {
23
+ startName += ctx.tokens[startPos]?.value ?? "";
24
+ startPos++;
25
+ startConsumed++;
26
+ }
27
+
22
28
  return options.strikeHyphens
23
29
  ? consumeRawNameSuffix(ctx, startPos, startConsumed, startName, options.hyphenatedNames)
24
30
  : consumeSafeNameSuffix(ctx, startPos, startConsumed, startName);
25
31
  }
26
32
 
27
33
  export function isAttributeNameToken(token: Token | undefined): token is Token {
28
- return token?.type === "TEXT" || token?.type === "IDENTIFIER";
34
+ return isAttributeWordToken(token) || token?.type === "UNDERSCORE";
29
35
  }
30
36
 
31
37
  function consumeSafeNameSuffix(
@@ -38,12 +44,8 @@ function consumeSafeNameSuffix(
38
44
  let pos = startPos;
39
45
  let consumed = startConsumed;
40
46
 
41
- while (
42
- ctx.tokens[pos]?.type === "TEXT" &&
43
- ctx.tokens[pos]?.value === "-" &&
44
- isAttributeNameToken(ctx.tokens[pos + 1])
45
- ) {
46
- name += "-";
47
+ while (isAttributeNameSeparator(ctx.tokens[pos]) && isAttributeWordToken(ctx.tokens[pos + 1])) {
48
+ name += ctx.tokens[pos]?.value ?? "";
47
49
  pos++;
48
50
  consumed++;
49
51
  name += ctx.tokens[pos]?.value ?? "";
@@ -65,20 +67,20 @@ function consumeRawNameSuffix(
65
67
  let pos = startPos;
66
68
  let consumed = startConsumed;
67
69
 
68
- while (isHyphenToken(ctx.tokens[pos])) {
69
- while (isHyphenToken(ctx.tokens[pos])) {
70
- if (hyphenatedNames) {
70
+ while (isAttributeNameSeparator(ctx.tokens[pos])) {
71
+ while (isAttributeNameSeparator(ctx.tokens[pos])) {
72
+ if (hyphenatedNames || ctx.tokens[pos]?.type === "UNDERSCORE") {
71
73
  name += ctx.tokens[pos]?.value ?? "-";
72
74
  }
73
75
  pos++;
74
76
  consumed++;
75
77
  }
76
78
 
77
- if (!isAttributeNameToken(ctx.tokens[pos])) {
79
+ if (!isAttributeWordToken(ctx.tokens[pos])) {
78
80
  break;
79
81
  }
80
82
 
81
- if (hyphenatedNames) {
83
+ if (hyphenatedNames || name.endsWith("_")) {
82
84
  name += ctx.tokens[pos]?.value ?? "";
83
85
  }
84
86
  pos++;
@@ -88,6 +90,14 @@ function consumeRawNameSuffix(
88
90
  return { name, pos, consumed };
89
91
  }
90
92
 
91
- function isHyphenToken(token: Token | undefined): boolean {
92
- return (token?.type === "TEXT" && token.value === "-") || token?.type === "STRIKE_MARKER";
93
+ function isAttributeWordToken(token: Token | undefined): boolean {
94
+ return token?.type === "TEXT" || token?.type === "IDENTIFIER";
95
+ }
96
+
97
+ function isAttributeNameSeparator(token: Token | undefined): boolean {
98
+ return (
99
+ (token?.type === "TEXT" && token.value === "-") ||
100
+ token?.type === "STRIKE_MARKER" ||
101
+ token?.type === "UNDERSCORE"
102
+ );
93
103
  }