@babel/template
Advanced tools
Comparing version 7.2.2 to 7.4.0
@@ -57,3 +57,4 @@ "use strict"; | ||
placeholderPattern: opts.placeholderPattern, | ||
preserveComments: opts.preserveComments | ||
preserveComments: opts.preserveComments, | ||
syntacticPlaceholders: opts.syntacticPlaceholders | ||
}); | ||
@@ -60,0 +61,0 @@ } while (metadata.placeholders.some(placeholder => placeholder.isDuplicate && nameSet.has(placeholder.name))); |
@@ -16,3 +16,4 @@ "use strict"; | ||
placeholderPattern = a.placeholderPattern, | ||
preserveComments = a.preserveComments | ||
preserveComments = a.preserveComments, | ||
syntacticPlaceholders = a.syntacticPlaceholders | ||
} = b; | ||
@@ -23,3 +24,4 @@ return { | ||
placeholderPattern, | ||
preserveComments | ||
preserveComments, | ||
syntacticPlaceholders | ||
}; | ||
@@ -37,5 +39,6 @@ } | ||
placeholderPattern, | ||
preserveComments | ||
preserveComments, | ||
syntacticPlaceholders | ||
} = _ref, | ||
parser = _objectWithoutPropertiesLoose(_ref, ["placeholderWhitelist", "placeholderPattern", "preserveComments"]); | ||
parser = _objectWithoutPropertiesLoose(_ref, ["placeholderWhitelist", "placeholderPattern", "preserveComments", "syntacticPlaceholders"]); | ||
@@ -54,2 +57,10 @@ if (placeholderWhitelist != null && !(placeholderWhitelist instanceof Set)) { | ||
if (syntacticPlaceholders != null && typeof syntacticPlaceholders !== "boolean") { | ||
throw new Error("'.syntacticPlaceholders' must be a boolean, null, or undefined"); | ||
} | ||
if (syntacticPlaceholders === true && (placeholderWhitelist != null || placeholderPattern != null)) { | ||
throw new Error("'.placeholderWhitelist' and '.placeholderPattern' aren't compatible" + " with '.syntacticPlaceholders: true'"); | ||
} | ||
return { | ||
@@ -59,3 +70,4 @@ parser, | ||
placeholderPattern: placeholderPattern == null ? undefined : placeholderPattern, | ||
preserveComments: preserveComments == null ? false : preserveComments | ||
preserveComments: preserveComments == null ? false : preserveComments, | ||
syntacticPlaceholders: syntacticPlaceholders == null ? undefined : syntacticPlaceholders | ||
}; | ||
@@ -62,0 +74,0 @@ } |
@@ -46,4 +46,5 @@ "use strict"; | ||
placeholderWhitelist, | ||
placeholderPattern = PATTERN, | ||
preserveComments | ||
placeholderPattern, | ||
preserveComments, | ||
syntacticPlaceholders | ||
} = opts; | ||
@@ -54,15 +55,24 @@ t().removePropertiesDeep(ast, { | ||
formatter.validate(ast); | ||
const placeholders = []; | ||
const placeholderNames = new Set(); | ||
const syntactic = { | ||
placeholders: [], | ||
placeholderNames: new Set() | ||
}; | ||
const legacy = { | ||
placeholders: [], | ||
placeholderNames: new Set() | ||
}; | ||
const isLegacyRef = { | ||
value: undefined | ||
}; | ||
t().traverse(ast, placeholderVisitorHandler, { | ||
placeholders, | ||
placeholderNames, | ||
syntactic, | ||
legacy, | ||
isLegacyRef, | ||
placeholderWhitelist, | ||
placeholderPattern | ||
placeholderPattern, | ||
syntacticPlaceholders | ||
}); | ||
return { | ||
ast, | ||
placeholders, | ||
placeholderNames | ||
}; | ||
return Object.assign({ | ||
ast | ||
}, isLegacyRef.value ? legacy : syntactic); | ||
} | ||
@@ -73,6 +83,17 @@ | ||
if (t().isIdentifier(node) || t().isJSXIdentifier(node)) { | ||
if (t().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) { | ||
return; | ||
} else if (t().isIdentifier(node) || t().isJSXIdentifier(node)) { | ||
name = node.name; | ||
state.isLegacyRef.value = true; | ||
} else if (t().isStringLiteral(node)) { | ||
name = node.value; | ||
state.isLegacyRef.value = true; | ||
} else { | ||
@@ -82,3 +103,7 @@ return; | ||
if ((!state.placeholderPattern || !state.placeholderPattern.test(name)) && (!state.placeholderWhitelist || !state.placeholderWhitelist.has(name))) { | ||
if (!state.isLegacyRef.value && (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.placeholderWhitelist || !state.placeholderWhitelist.has(name))) { | ||
return; | ||
@@ -94,9 +119,13 @@ } | ||
if (t().isStringLiteral(node)) { | ||
if (t().isStringLiteral(node) || t().isPlaceholder(node, { | ||
expectedNode: "StringLiteral" | ||
})) { | ||
type = "string"; | ||
} else if (t().isNewExpression(parent) && key === "arguments" || t().isCallExpression(parent) && key === "arguments" || t().isFunction(parent) && key === "params") { | ||
type = "param"; | ||
} else if (t().isExpressionStatement(parent)) { | ||
} else if (t().isExpressionStatement(parent) && !t().isPlaceholder(node)) { | ||
type = "statement"; | ||
ancestors = ancestors.slice(0, -1); | ||
} else if (t().isStatement(node) && t().isPlaceholder(node)) { | ||
type = "statement"; | ||
} else { | ||
@@ -106,9 +135,13 @@ type = "other"; | ||
state.placeholders.push({ | ||
const { | ||
placeholders, | ||
placeholderNames | ||
} = state.isLegacyRef.value ? state.legacy : state.syntactic; | ||
placeholders.push({ | ||
name, | ||
type, | ||
resolve: ast => resolveAncestors(ast, ancestors), | ||
isDuplicate: state.placeholderNames.has(name) | ||
isDuplicate: placeholderNames.has(name) | ||
}); | ||
state.placeholderNames.add(name); | ||
placeholderNames.add(name); | ||
} | ||
@@ -148,3 +181,5 @@ | ||
sourceType: "module" | ||
}, parserOpts); | ||
}, parserOpts, { | ||
plugins: (parserOpts.plugins || []).concat("placeholders") | ||
}); | ||
@@ -151,0 +186,0 @@ try { |
{ | ||
"name": "@babel/template", | ||
"version": "7.2.2", | ||
"version": "7.4.0", | ||
"description": "Generate an AST from a string template.", | ||
@@ -15,5 +15,6 @@ "author": "Sebastian McKenzie <sebmck@gmail.com>", | ||
"@babel/code-frame": "^7.0.0", | ||
"@babel/parser": "^7.2.2", | ||
"@babel/types": "^7.2.2" | ||
} | ||
"@babel/parser": "^7.4.0", | ||
"@babel/types": "^7.4.0" | ||
}, | ||
"gitHead": "f1328fb913b5a93d54dfc6e3728b1f56c8f4a804" | ||
} |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
23019
582
0
Updated@babel/parser@^7.4.0
Updated@babel/types@^7.4.0