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

@riotjs/compiler

Package Overview
Dependencies
Maintainers
1
Versions
126
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@riotjs/compiler - npm Package Compare versions

Comparing version 4.0.0-beta.1 to 4.0.0-beta.2

3

CHANGELOG.md
# Compiler Changes
### v4.0.0-beta.2
- Add support for multiple expressions on the same attribute node
### v4.0.0-beta.1

@@ -4,0 +7,0 @@ - Update rename the `tag` property `exports`

8

package.json
{
"name": "@riotjs/compiler",
"version": "4.0.0-beta.1",
"version": "4.0.0-beta.2",
"description": "Compiler for riot .tag files",

@@ -37,3 +37,3 @@ "main": "dist/index.js",

"coveralls": "^3.0.3",
"eslint": "^5.15.0",
"eslint": "^5.15.2",
"eslint-config-riot": "^2.0.0",

@@ -43,3 +43,3 @@ "mocha": "^6.0.2",

"reify": "^0.18.1",
"rollup": "^1.4.0",
"rollup": "^1.6.0",
"rollup-plugin-alias": "^1.5.1",

@@ -59,3 +59,3 @@ "rollup-plugin-commonjs": "^9.2.1",

"dependencies": {
"@riotjs/dom-bindings": "^0.5.0",
"@riotjs/dom-bindings": "^0.11.2",
"@riotjs/parser": "^0.8.1",

@@ -62,0 +62,0 @@ "curri": "^1.0.0",

@@ -8,7 +8,32 @@ import {

} from '../constants'
import {hasExpressions, isSpreadAttribute, toScopedFunction} from '../utils'
import {createArrayString, hasExpressions, isSpreadAttribute, transformExpression, wrapASTInFunctionWithScope} from '../utils'
import {nullNode, simplePropertyNode} from '../../../utils/custom-ast-nodes'
import {builders} from '../../../utils/build-types'
/**
* Simple expression bindings might contain multiple expressions like for example: "class="{foo} red {bar}""
* This helper aims to merge them in a template literal if it's necessary
* @param {RiotParser.Attr} node - riot parser node
* @param {string} sourceFile - original tag file
* @param {string} sourceCode - original tag source code
* @returns { Object } a template literal expression object
*/
export function mergeAttributeExpressions(node, sourceFile, sourceCode) {
if (!node.parts)
return transformExpression(node.expressions[0], sourceFile, sourceCode)
const stringsArray = node.parts.reduce((acc, str) => {
const expression = node.expressions.find(e => e.text === str)
return [
...acc,
expression ? transformExpression(expression, sourceFile, sourceCode) : builders.literal(str)
]
}, [])
return createArrayString(stringsArray)
}
/**
* Create a simple attribute expression

@@ -34,3 +59,3 @@ * @param {RiotParser.Node.Attr} sourceNode - the custom tag

// dynamic attribute
toScopedFunction(sourceNode.expressions[0], sourceFile, sourceCode) :
wrapASTInFunctionWithScope(mergeAttributeExpressions(sourceNode, sourceFile, sourceCode)) :
// static attribute

@@ -37,0 +62,0 @@ builders.functionExpression(

@@ -8,4 +8,4 @@ import {

} from '../constants'
import {createArrayString, transformExpression, wrapASTInFunctionWithScope} from '../utils'
import {nullNode,simplePropertyNode} from '../../../utils/custom-ast-nodes'
import {transformExpression, wrapASTInFunctionWithScope} from '../utils'
import {builders} from '../../../utils/build-types'

@@ -58,12 +58,5 @@ import {isLiteral} from '../../../utils/ast-nodes-checks'

// filter the empty literal expressions
.filter(expr => !isLiteral(expr) || expr.value) // eslint-disable-line
.filter(expr => !isLiteral(expr) || expr.value)
return builders.callExpression(
builders.memberExpression(
builders.arrayExpression(stringsArray),
builders.identifier('join'),
false
),
[builders.literal('')],
)
return createArrayString(stringsArray)
}

@@ -70,0 +63,0 @@

@@ -563,2 +563,17 @@ import {

/**
* Create a strings array with the `join` call to transform it into a string
* @param {Array} stringsArray - array containing all the strings to concatenate
* @returns {AST.CallExpression} array with a `join` call
*/
export function createArrayString(stringsArray) {
return builders.callExpression(
builders.memberExpression(
builders.arrayExpression(stringsArray),
builders.identifier('join'),
false
),
[builders.literal('')],
)
}

@@ -565,0 +580,0 @@ /**

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

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