Skip to content

Commit

Permalink
Fix js variable regular expression
Browse files Browse the repository at this point in the history
  • Loading branch information
FilipRazek committed Jan 24, 2024
1 parent 7de2ae4 commit 9e306e1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/language-html/embed/constants.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions src/language-html/embed/vue-bindings.js
@@ -1,4 +1,5 @@
import { formatAttributeValue } from "./utils.js";
import { JS_VARIABLE_RE } from "./constants.js";

/**
* @typedef {import("../../document/builders.js").Doc} Doc
Expand All @@ -19,8 +20,11 @@ function isVueEventBindingExpression(eventBindingValue) {
// arrow function or anonymous function
const fnExpRE = /^(?:[\w$]+|\([^)]*\))\s*=>|^function\s*\(/;
// simple member expression chain (a, a.b, a['b'], a["b"], a[0], a[b])
const simplePathRE =
/^[$_a-z][\w$]*(?:\.[$_a-z][\w$]*|\['[^']*']|\["[^"]*"]|\[\d+]|\[[$_a-z][\w$]*])*$/i;

const simplePathRE = new RegExp(
String.raw`^${JS_VARIABLE_RE}(?:\.${JS_VARIABLE_RE}|\['[^']*']|\["[^"]*"]|\[\d+]|\[${JS_VARIABLE_RE}])*$`,
"i",
);

// https://github.com/vuejs/vue/blob/v2.5.17/src/compiler/helpers.js#L104
const value = eventBindingValue.trim();
Expand Down

0 comments on commit 9e306e1

Please sign in to comment.