@babel/template
Advanced tools
Comparing version 7.20.7 to 7.22.5
@@ -34,19 +34,18 @@ "use strict"; | ||
function buildLiteralData(formatter, tpl, opts) { | ||
let names; | ||
let nameSet; | ||
let metadata; | ||
let prefix = ""; | ||
let prefix = "BABEL_TPL$"; | ||
const raw = tpl.join(""); | ||
do { | ||
prefix += "$"; | ||
const result = buildTemplateCode(tpl, prefix); | ||
names = result.names; | ||
nameSet = new Set(names); | ||
metadata = (0, _parse.default)(formatter, formatter.code(result.code), { | ||
parser: opts.parser, | ||
placeholderWhitelist: new Set(result.names.concat(opts.placeholderWhitelist ? Array.from(opts.placeholderWhitelist) : [])), | ||
placeholderPattern: opts.placeholderPattern, | ||
preserveComments: opts.preserveComments, | ||
syntacticPlaceholders: opts.syntacticPlaceholders | ||
}); | ||
} while (metadata.placeholders.some(placeholder => placeholder.isDuplicate && nameSet.has(placeholder.name))); | ||
prefix = "$$" + prefix; | ||
} while (raw.includes(prefix)); | ||
const { | ||
names, | ||
code | ||
} = buildTemplateCode(tpl, prefix); | ||
const metadata = (0, _parse.default)(formatter, formatter.code(code), { | ||
parser: opts.parser, | ||
placeholderWhitelist: new Set(names.concat(opts.placeholderWhitelist ? Array.from(opts.placeholderWhitelist) : [])), | ||
placeholderPattern: opts.placeholderPattern, | ||
preserveComments: opts.preserveComments, | ||
syntacticPlaceholders: opts.syntacticPlaceholders | ||
}); | ||
return { | ||
@@ -53,0 +52,0 @@ metadata, |
@@ -11,3 +11,2 @@ "use strict"; | ||
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } | ||
function merge(a, b) { | ||
@@ -14,0 +13,0 @@ const { |
@@ -36,24 +36,19 @@ "use strict"; | ||
formatter.validate(ast); | ||
const syntactic = { | ||
placeholders: [], | ||
placeholderNames: new Set() | ||
}; | ||
const legacy = { | ||
placeholders: [], | ||
placeholderNames: new Set() | ||
}; | ||
const isLegacyRef = { | ||
value: undefined | ||
}; | ||
traverse(ast, placeholderVisitorHandler, { | ||
syntactic, | ||
legacy, | ||
isLegacyRef, | ||
const state = { | ||
syntactic: { | ||
placeholders: [], | ||
placeholderNames: new Set() | ||
}, | ||
legacy: { | ||
placeholders: [], | ||
placeholderNames: new Set() | ||
}, | ||
placeholderWhitelist, | ||
placeholderPattern, | ||
syntacticPlaceholders | ||
}); | ||
}; | ||
traverse(ast, placeholderVisitorHandler, state); | ||
return Object.assign({ | ||
ast | ||
}, isLegacyRef.value ? legacy : syntactic); | ||
}, state.syntactic.placeholders.length ? state.syntactic : state.legacy); | ||
} | ||
@@ -63,27 +58,24 @@ function placeholderVisitorHandler(node, ancestors, state) { | ||
let name; | ||
let hasSyntacticPlaceholders = state.syntactic.placeholders.length > 0; | ||
if (isPlaceholder(node)) { | ||
if (state.syntacticPlaceholders === false) { | ||
throw new Error("%%foo%%-style placeholders can't be used when " + "'.syntacticPlaceholders' is false."); | ||
} else { | ||
name = node.name.name; | ||
state.isLegacyRef.value = false; | ||
} | ||
} else if (state.isLegacyRef.value === false || state.syntacticPlaceholders) { | ||
name = node.name.name; | ||
hasSyntacticPlaceholders = true; | ||
} else if (hasSyntacticPlaceholders || state.syntacticPlaceholders) { | ||
return; | ||
} else if (isIdentifier(node) || isJSXIdentifier(node)) { | ||
name = node.name; | ||
state.isLegacyRef.value = true; | ||
} else if (isStringLiteral(node)) { | ||
name = node.value; | ||
state.isLegacyRef.value = true; | ||
} else { | ||
return; | ||
} | ||
if (!state.isLegacyRef.value && (state.placeholderPattern != null || state.placeholderWhitelist != null)) { | ||
if (hasSyntacticPlaceholders && (state.placeholderPattern != null || state.placeholderWhitelist != null)) { | ||
throw new Error("'.placeholderWhitelist' and '.placeholderPattern' aren't compatible" + " with '.syntacticPlaceholders: true'"); | ||
} | ||
if (state.isLegacyRef.value && (state.placeholderPattern === false || !(state.placeholderPattern || PATTERN).test(name)) && !((_state$placeholderWhi = state.placeholderWhitelist) != null && _state$placeholderWhi.has(name))) { | ||
if (!hasSyntacticPlaceholders && (state.placeholderPattern === false || !(state.placeholderPattern || PATTERN).test(name)) && !((_state$placeholderWhi = state.placeholderWhitelist) != null && _state$placeholderWhi.has(name))) { | ||
return; | ||
} | ||
ancestors = ancestors.slice(); | ||
@@ -112,3 +104,3 @@ const { | ||
placeholderNames | ||
} = state.isLegacyRef.value ? state.legacy : state.syntactic; | ||
} = !hasSyntacticPlaceholders ? state.legacy : state.syntactic; | ||
placeholders.push({ | ||
@@ -115,0 +107,0 @@ name, |
@@ -37,3 +37,2 @@ "use strict"; | ||
} | ||
metadata.placeholders.slice().reverse().forEach(placeholder => { | ||
@@ -40,0 +39,0 @@ try { |
{ | ||
"name": "@babel/template", | ||
"version": "7.20.7", | ||
"version": "7.22.5", | ||
"description": "Generate an AST from a string template.", | ||
@@ -19,5 +19,5 @@ "author": "The Babel Team (https://babel.dev/team)", | ||
"dependencies": { | ||
"@babel/code-frame": "^7.18.6", | ||
"@babel/parser": "^7.20.7", | ||
"@babel/types": "^7.20.7" | ||
"@babel/code-frame": "^7.22.5", | ||
"@babel/parser": "^7.22.5", | ||
"@babel/types": "^7.22.5" | ||
}, | ||
@@ -24,0 +24,0 @@ "engines": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
69045
593
Updated@babel/code-frame@^7.22.5
Updated@babel/parser@^7.22.5
Updated@babel/types@^7.22.5