Socket
Socket
Sign inDemoInstall

@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 5.4.2 to 6.0.0

src/generators/javascript/utils.js

31

package.json
{
"name": "@riotjs/compiler",
"version": "5.4.2",
"version": "6.0.0",
"description": "Compiler for riot .tag files",

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

"lint": "eslint src/ test/ build/",
"cov": "nyc report --reporter=text-lcov | coveralls",
"cov": "nyc report --reporter=lcov",
"cov-html": "nyc report --reporter=html",

@@ -39,22 +39,21 @@ "build": "rollup -c build/rollup.node.config.js && rollup -c build/rollup.browser.config.js",

"devDependencies": {
"@babel/core": "^7.14.0",
"@babel/preset-env": "^7.14.1",
"@riotjs/dom-bindings": "^5.0.5",
"@babel/core": "^7.14.6",
"@babel/preset-env": "^7.14.7",
"@riotjs/dom-bindings": "^5.1.3",
"@rollup/plugin-alias": "^3.1.2",
"@rollup/plugin-commonjs": "^18.1.0",
"@rollup/plugin-commonjs": "^19.0.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.0.0",
"chai": "^4.3.4",
"coveralls": "^3.1.0",
"eslint": "^7.25.0",
"eslint": "^7.30.0",
"eslint-config-riot": "^3.0.0",
"esm": "^3.2.25",
"mocha": "^8.3.2",
"node-sass": "^5.0.0",
"mocha": "^8.4.0",
"node-sass": "^6.0.1",
"nyc": "^15.1.0",
"pug": "^3.0.2",
"rollup": "^2.47.0",
"rollup-plugin-node-builtins": "^2.1.2",
"rollup": "^2.53.1",
"rollup-plugin-node-builtins": "^2.0.0",
"shelljs": "^0.8.4",
"typescript": "^4.2.4"
"typescript": "^4.3.5"
},

@@ -68,5 +67,5 @@ "author": "Gianluca Guarini <gianluca.guarini@gmail.com> (http://gianlucaguarini.com)",

"dependencies": {
"@babel/parser": "^7.14.7",
"@riotjs/parser": "^4.3.1",
"@babel/parser": "^7.14.1",
"@riotjs/util": "2.0.2",
"@riotjs/util": "2.0.4",
"cssesc": "^3.0.0",

@@ -76,3 +75,3 @@ "cumpa": "^1.0.1",

"dom-nodes": "^1.1.3",
"globals": "^13.8.0",
"globals": "^13.10.0",
"recast": "^0.20.4",

@@ -79,0 +78,0 @@ "source-map": "^0.7.3"

export const TAG_LOGIC_PROPERTY = 'exports'
export const TAG_CSS_PROPERTY = 'css'
export const TAG_TEMPLATE_PROPERTY = 'template'
export const TAG_NAME_PROPERTY = 'name'
export const TAG_NAME_PROPERTY = 'name'
export const RIOT_MODULE_ID = 'riot'
export const RIOT_INTERFACE_WRAPPER_NAME = 'RiotComponentWrapper'
export const RIOT_TAG_INTERFACE_NAME = 'RiotComponent'

@@ -1,4 +0,10 @@

import {builders, types} from '../../utils/build-types'
import {isExportDefaultStatement, isImportDeclaration, isThisExpressionStatement} from '../../utils/ast-nodes-checks'
import {TAG_LOGIC_PROPERTY} from '../../constants'
import {
addComponentInterfaceToExportedObject,
createDefaultExportFromLegacySyntax,
extendTagProperty,
filterNonExportDefaultStatements,
findAllImportDeclarations, findComponentInterface,
findExportDefaultStatement,
getProgramBody
} from './utils'
import addLinesOffset from '../../utils/add-lines-offset'

@@ -9,2 +15,3 @@ import generateAST from '../../utils/generate-ast'

import {isNil} from '@riotjs/util/checks'
import {isThisExpressionStatement} from '../../utils/ast-nodes-checks'
import preprocess from '../../utils/preprocess-node'

@@ -14,86 +21,2 @@ import sourcemapToJSON from '../../utils/sourcemap-as-json'

/**
* Find the export default statement
* @param { Array } body - tree structure containing the program code
* @returns { Object } node containing only the code of the export default statement
*/
function findExportDefaultStatement(body) {
return body.find(isExportDefaultStatement)
}
/**
* Find all import declarations
* @param { Array } body - tree structure containing the program code
* @returns { Array } array containing all the import declarations detected
*/
function findAllImportDeclarations(body) {
return body.filter(isImportDeclaration)
}
/**
* Filter all the import declarations
* @param { Array } body - tree structure containing the program code
* @returns { Array } array containing all the ast expressions without the import declarations
*/
function filterOutAllImportDeclarations(body) {
return body.filter(n => !isImportDeclaration(n))
}
/**
* Create the default export declaration interpreting the old riot syntax relying on "this" statements
* @param { Array } body - tree structure containing the program code
* @returns { Object } ExportDefaultDeclaration
*/
function createDefaultExportFromLegacySyntax(body) {
return builders.exportDefaultDeclaration(
builders.functionDeclaration(
builders.identifier(TAG_LOGIC_PROPERTY),
[],
builders.blockStatement([
...filterOutAllImportDeclarations(body),
builders.returnStatement(builders.thisExpression())
])
)
)
}
/**
* Find all the code in an ast program except for the export default statements
* @param { Array } body - tree structure containing the program code
* @returns { Array } array containing all the program code except the export default expressions
*/
function filterNonExportDefaultStatements(body) {
return body.filter(node => !isExportDefaultStatement(node) && !isThisExpressionStatement(node))
}
/**
* Get the body of the AST structure
* @param { Object } ast - ast object generated by recast
* @returns { Array } array containing the program code
*/
function getProgramBody(ast) {
return ast.body || ast.program.body
}
/**
* Extend the AST adding the new tag method containing our tag sourcecode
* @param { Object } ast - current output ast
* @param { Object } exportDefaultNode - tag export default node
* @returns { Object } the output ast having the "tag" key extended with the content of the export default
*/
function extendTagProperty(ast, exportDefaultNode) {
types.visit(ast, {
visitProperty(path) {
if (path.value.key.value === TAG_LOGIC_PROPERTY) {
path.value.value = exportDefaultNode.declaration
return false
}
this.traverse(path)
}
})
return ast
}
/**
* Generate the component javascript logic

@@ -123,2 +46,3 @@ * @param { Object } sourceNode - node generated by the riot compiler

const outputBody = getProgramBody(ast)
const componentInterface = findComponentInterface(generatedAstBody)

@@ -148,3 +72,6 @@ // throw in case of mixed component exports

return ast
return componentInterface ?
// add the component interface to the component object exported
addComponentInterfaceToExportedObject(ast, componentInterface) :
ast
}

@@ -17,3 +17,3 @@ import {constants} from '@riotjs/parser'

export const TEMPLATE_FN = 'template'
export const SCOPE = 'scope'
export const SCOPE = '_scope'
export const GET_COMPONENT_FN = 'getComponent'

@@ -20,0 +20,0 @@

@@ -20,2 +20,5 @@ import globalScope from 'globals'

export const isImportDeclaration = n => namedTypes.ImportDeclaration.check(n)
export const isTypeAliasDeclaration = n => namedTypes.TSTypeAliasDeclaration.check(n)
export const isInterfaceDeclaration = n => namedTypes.TSInterfaceDeclaration.check(n)
export const isExportNamedDeclaration = n => namedTypes.ExportNamedDeclaration.check(n)

@@ -22,0 +25,0 @@ export const isBrowserAPI = ({name}) => browserAPIs.includes(name)

@@ -1,2 +0,2 @@

import {parse as customParser} from 'recast/parsers/babel'
import {parse as customParser} from 'recast/parsers/typescript'
import {parse} from 'recast'

@@ -3,0 +3,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