sugar-high 0.0.7 → 0.0.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.
Files changed (2) hide show
  1. package/lib/index.mjs +22 -15
  2. package/package.json +1 -1
package/lib/index.mjs CHANGED
@@ -163,8 +163,11 @@ export function tokenize(code) {
163
163
  /** @type {{ tag: boolean; child: boolean; expr: boolean }} */
164
164
  const jsx = { tag: false, child: false, expr: false }
165
165
 
166
+ const inJsxLiterals = () => !jsx.tag && jsx.child && !jsx.expr
167
+
166
168
  function classify(token) {
167
- if (isCommentStart(token[0] + token[1])) {
169
+ const [chr0, chr1] = [token[0], token[1]]
170
+ if (isCommentStart(chr0 + chr1)) {
168
171
  return T_COMMENT
169
172
  } else if (keywords.has(token)) {
170
173
  return T_KEYWORD
@@ -173,19 +176,23 @@ export function tokenize(code) {
173
176
  } else if (
174
177
  (
175
178
  // is quoted string
176
- (isStringQuotation(token[0]) && !isStringQuotation(token[1])) ||
179
+ (isStringQuotation(chr0) && !isStringQuotation(chr1)) ||
177
180
  // is regex
178
- (!jsx.tag && isRegexStart(token[0] + token[1]) && token[token.length - 1] === '/')
181
+ (!jsx.tag && isRegexStart(chr0 + chr1) && token[token.length - 1] === '/')
179
182
  )
180
183
  ) {
181
184
  return T_STRING
182
185
  } else if (token === ' ') {
183
186
  return T_SPACE
184
- } else if (signs.has(token[0])) {
187
+ } else if (signs.has(chr0)) {
185
188
  return T_SIGN
186
189
  } else if (
187
- token[0] === token[0].toUpperCase() ||
188
- token === 'null'
190
+ !inJsxLiterals() &&
191
+ (
192
+ isIdentifierChar(chr0) &&
193
+ chr0 === chr0.toUpperCase() ||
194
+ token === 'null'
195
+ )
189
196
  ) {
190
197
  return T_CLS_NUMBER
191
198
  } else {
@@ -205,8 +212,8 @@ export function tokenize(code) {
205
212
  const prev = code[i - 1]
206
213
  const next = code[i + 1]
207
214
  const c_n = curr + next // current and next
208
- const p_c = prev + curr // previous and current
209
- const isJsxLiterals = !jsx.tag && jsx.child && !jsx.expr
215
+ const p_c = prev + curr // previous and current
216
+ const isJsxLiterals = inJsxLiterals()
210
217
 
211
218
  if (jsx.tag) {
212
219
  const isOpenElementEnd = curr === '>'
@@ -219,13 +226,6 @@ export function tokenize(code) {
219
226
  jsx.tag = true
220
227
  jsx.child = false
221
228
  }
222
-
223
- if (jsx.child && curr === '{') {
224
- jsx.expr = true
225
- }
226
- if (jsx.child && jsx.expr && curr === '}') {
227
- jsx.expr = false
228
- }
229
229
 
230
230
  if (
231
231
  !string.entered &&
@@ -296,6 +296,13 @@ export function tokenize(code) {
296
296
  else if (jsxBrackets.has(curr)) append()
297
297
  }
298
298
  }
299
+
300
+ if (jsx.child && curr === '{') {
301
+ jsx.expr = true
302
+ }
303
+ if (jsx.child && jsx.expr && curr === '}') {
304
+ jsx.expr = false
305
+ }
299
306
  }
300
307
 
301
308
  append()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sugar-high",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "type": "module",
5
5
  "exports": "./lib/index.mjs",
6
6
  "description": "Super lightweight JSX syntax highlighter",