Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pure-engine

Package Overview
Dependencies
Maintainers
1
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pure-engine - npm Package Compare versions

Comparing version 0.10.1 to 0.10.2

src/Component/curlyTagReduction.js

6

package.json
{
"name": "pure-engine",
"version": "0.10.1",
"version": "0.10.2",
"description": "Compile HTML templates into JS",

@@ -44,3 +44,3 @@ "main": "index.js",

"abstract-syntax-tree": "^2.0.1",
"astoptech": "^1.0.4",
"astoptech": "^1.0.6",
"asttv": "^1.0.1",

@@ -62,3 +62,3 @@ "css-tree": "^1.0.0-alpha.29",

"ansi-colors": "^3.2.1",
"ava": "^1.1.0",
"ava": "^1.2.0",
"babel-loader": "^8.0.4",

@@ -65,0 +65,0 @@ "babel-plugin-transform-react-jsx": "^6.24.1",

@@ -34,2 +34,3 @@ const AbstractSyntaxTree = require('abstract-syntax-tree')

const { wordsToNumbers } = require('words-to-numbers')
const Component = require('./Component')
let asyncCounter = 0

@@ -114,2 +115,11 @@

function collectInlineComponents (fragment, attributes, components) {
const { key } = attributes[attributes.length - 1]
const { content } = fragment.children[0]
components.push({ name: key, content, path: null })
fragment.children.forEach(child => {
child.used = true
})
}
function convertValueToNode (value, variables) {

@@ -150,5 +160,15 @@ if (isCurlyTag(value)) {

const htmlTree = parse(component.content)
let content
const htmlComponent = new Component(component.content, localVariables)
try {
htmlComponent.optimize()
content = htmlComponent.source
} catch (exception) {
// TODO handle expception, add extra specs
content = component.content
}
const htmlTree = parse(content)
let children = fragment.children
plugins.forEach(plugin => { plugin.beforeprerun() })
walk(htmlTree, leaf => {

@@ -159,8 +179,8 @@ try {

plugins.forEach(plugin => {
plugin.prepare({
plugin.prerun({
tag: leaf.tagName,
keys,
attrs,
fragment: leaf,
options,
fragment: leaf,
...leaf

@@ -193,3 +213,3 @@ })

})
plugins.forEach(plugin => { plugin.afterprerun() })
walk(htmlTree, leaf => {

@@ -213,2 +233,5 @@ const attrs = leaf.attributes || []

if (leaf.tagName === component.name) {
// TODO allow inlined components to have
// the same name as imported one
// the limitation can be unexpected
leaf.root = true

@@ -262,6 +285,7 @@ }

})
const currentComponents = []
let slots = 0
walk(htmlTree, async (current, parent) => {
const attrs = current.attributes || []
const keys = attrs.map(attr => attr.key)
if (current.tagName === 'import' || current.tagName === 'require') {

@@ -273,2 +297,7 @@ collectComponentsFromImport(current, statistics, currentComponents, component, options)

collectComponentsFromPartialAttribute(current, statistics, options)
} else if (
(current.tagName === 'template' && keys.length > 0) ||
(current.tagName === 'script' && keys.includes('component'))
) {
collectInlineComponents(current, attrs, currentComponents)
}

@@ -475,8 +504,15 @@ const currentComponent = currentComponents.find(component => component.name === current.tagName)

// e.g. this possibly will cause issues if the identifier is a part of a more complex node
// similar code is in the getTemplateNode / convert.js
// we could consider changing the variables format and having info if it's a local or global
// variable and inline it there
// so that the replacement code is only in one place
ast.replace({
enter: node => {
if (node.type === 'Identifier') {
if (node.type === 'Identifier' && !node.inlined && !node.omit) {
const variable = localVariables.find(variable => variable.key === node.name)
if (variable) {
return convertText(variable.value, variables, filters, translations, languages, translationsPaths)[0]
const node = convertText(variable.value, [], filters, translations, languages, translationsPaths, true)[0]
AbstractSyntaxTree.walk(node, leaf => { leaf.inlined = true })
return node
}

@@ -494,2 +530,7 @@ }

})
} else if (
(tag === 'template' && keys.length > 0) ||
(tag === 'script' && keys.includes('component'))
) {
collectInlineComponents(fragment, attrs, components)
} else if ((tag === 'script' && keys.includes('inline')) || options.inline.includes('scripts')) {

@@ -496,0 +537,0 @@ if (keys.includes('src')) {

@@ -15,2 +15,3 @@ const AbstractSyntaxTree = require('abstract-syntax-tree')

const InternationalizationPlugin = require('./plugins/InternationalizationPlugin')
const BoxModelPlugin = require('./plugins/BoxModelPlugin')

@@ -33,2 +34,3 @@ async function render (htmltree, options) {

const plugins = [
new BoxModelPlugin(),
new CurlyStylesPlugin(),

@@ -40,2 +42,3 @@ new ScopedStylesPlugin(),

tree.append(getTemplateVariableDeclaration(TEMPLATE_VARIABLE))
plugins.forEach(plugin => { plugin.beforeprerun() })
walk(htmltree, async fragment => {

@@ -45,3 +48,3 @@ try {

plugins.forEach(plugin => {
plugin.prepare({
plugin.prerun({
tag: fragment.tagName,

@@ -59,2 +62,3 @@ keys: attrs.map(attribute => attribute.key),

})
plugins.forEach(plugin => { plugin.afterprerun() })

@@ -61,0 +65,0 @@ walk(htmltree, async fragment => {

@@ -173,7 +173,7 @@ const { OBJECT_VARIABLE, ESCAPE_VARIABLE, BOOLEAN_ATTRIBUTES, UNESCAPED_NAMES, GLOBAL_VARIABLES, RESERVED_KEYWORDS } = require('./enum')

node.omit = true
} else if (node.type === 'MemberExpression' && node.property.type === 'Identifier' && !node.computed) {
node.property.omit = true
} else if (node.type === 'MemberExpression') {
if (node.property.type === 'Identifier' && !node.computed) node.property.omit = true
} else if (node.type === 'Identifier' && !node.omit && !GLOBAL_VARIABLES.includes(node.name)) {
node.omit = true
if (!variables.includes(node.name)) {
node.omit = true
const object = getIdentifier(OBJECT_VARIABLE)

@@ -184,3 +184,4 @@ object.omit = true

object,
property: node
property: node,
omit: true
}

@@ -209,3 +210,3 @@ }

function convertText (text, variables, currentFilters, translations, languages, translationsPaths) {
function convertText (text, variables, currentFilters, translations, languages, translationsPaths, unescaped = false) {
const nodes = extract(text).map(({ value, filters = [] }, index) => {

@@ -217,3 +218,3 @@ if (value.includes('{') && value.includes('}')) {

const name = expression.name
let unescape = name ? UNESCAPED_NAMES.includes(name) : false
let unescape = unescaped || UNESCAPED_NAMES.includes(name)
if (!unescape) {

@@ -220,0 +221,0 @@ filters.forEach(filter => {

const { parseDefaults } = require('himalaya')
const { VOID_TAGS } = require('../enum')
function regexp (tag, name) {
return new RegExp(`<${tag}\\s+${name}\\s+`)
}
function deduceVoidTags (source) {
return VOID_TAGS.concat(parseDefaults.voidTags).filter(name => {
return !regexp('import', name).test(source) && !regexp('require', name).test(source)
})
}
module.exports = function defaults (source, options) {
const voidTags = VOID_TAGS.concat(parseDefaults.voidTags).filter(tag => {
const regexp = new RegExp(`<import\\s+${tag}\\s+`)
return !regexp.test(source)
})
const voidTags = deduceVoidTags(source)
// we could also potentially decide if the tag is self closing (void)

@@ -10,0 +17,0 @@ // based on the existence of a slot inside of the component

const { stringify } = require('himalaya')
const defaults = require('./defaults')
module.exports = function (source, options) {
return stringify(source, defaults(source, options))
// TODO: Clean up to receive two parameters.
module.exports = function (tree, source, options) {
return stringify(tree, defaults(source, options))
}
const {
memberExpressionReduction,
logicalExpressionReduction,

@@ -25,2 +26,3 @@ binaryExpressionReduction,

// can the below be done in one walk?
this.program.replace({ enter: memberExpressionReduction })
this.program.replace({ enter: logicalExpressionReduction })

@@ -27,0 +29,0 @@ this.program.replace({ enter: binaryExpressionReduction })

@@ -5,2 +5,3 @@ const { isCurlyTag, getExpressionFromCurlyTag } = require('../string')

const { flatten } = require('pure-utilities/object')
const Plugin = require('./Plugin')

@@ -25,7 +26,8 @@ function dasherize (string) {

class CurlyStylesPlugin {
class CurlyStylesPlugin extends Plugin {
constructor () {
super()
this.scopes = []
}
prepare ({ keys, fragment, attrs }) {
prerun ({ keys, fragment, attrs }) {
function inline (name) {

@@ -32,0 +34,0 @@ if (keys.includes(name)) {

@@ -8,2 +8,3 @@ const { readFileSync } = require('fs')

const { getTemplateAssignmentExpression, getTranslateCallExpression } = require('../factory')
const Plugin = require('./Plugin')

@@ -75,4 +76,5 @@ function parseYAML (content) {

class InternationalizationPlugin {
class InternationalizationPlugin extends Plugin {
constructor ({ translations, statistics, filters }) {
super()
this.translations = translations

@@ -82,3 +84,3 @@ this.statistics = statistics

}
prepare ({ tag, attrs, keys, fragment, options }) {
prerun ({ tag, attrs, keys, fragment, options }) {
if ((tag === 'script' && keys.includes('i18n')) || tag === 'i18n') {

@@ -85,0 +87,0 @@ fragment.used = true

@@ -6,2 +6,3 @@ const { parse, walk, generate } = require('css-tree')

const { extractValues } = require('../string')
const Plugin = require('./Plugin')

@@ -46,7 +47,8 @@ function addScopeToCssSelectors (node, scopes) {

class ScopedStylesPlugin {
class ScopedStylesPlugin extends Plugin {
constructor () {
super()
this.scopes = []
}
prepare ({ tag, keys, children }) {
prerun ({ tag, keys, children }) {
if (tag === 'style' && keys.includes('scoped')) {

@@ -53,0 +55,0 @@ children.forEach(node => addScopeToCssSelectors(node, this.scopes))

const { ltrim } = require('pure-utilities/string')
const lexer = require('./lexer')
function curlyTag (string) {
return `{${string}}`
}
function isCurlyTag (value) {

@@ -58,2 +62,2 @@ return value && value.startsWith('{') && value.endsWith('}')

module.exports = {extract, extractValues, getName, isCurlyTag, getExpressionFromCurlyTag}
module.exports = {extract, extractValues, getName, isCurlyTag, getExpressionFromCurlyTag, curlyTag}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc