New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@ordergroove/smi-precompile

Package Overview
Dependencies
Maintainers
4
Versions
81
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ordergroove/smi-precompile - npm Package Compare versions

Comparing version 1.6.1 to 1.6.2-alpha-PR-542-24.329

browser-shim.js

37

__tests__/precompile.spec.js

@@ -353,1 +353,38 @@ /* eslint-disable no-template-curly-in-string */

});
describe('setting optimization', () => {
test('should replace false literals with expression alternae', () => {
const newLocal = ` {% if ('some_setting_always_false' | setting) %} always true {% endif %}
`;
[0, undefined, '', false, -0, null, NaN, ``, ''].forEach(some_setting_always_false => {
const result = precompile(newLocal, {}, [], {
some_setting_always_false
});
expect(result).not.toContain('always true');
});
});
test('should replace truthy literals with expression subsequent', () => {
const newLocal = ` {% if ('some_setting_always_true' | setting) %} always true {% else %} always false{% endif %}
`;
[true, 1, {}, [], '0'].forEach(some_setting_always_true => {
const result = precompile(newLocal, {}, [], {
some_setting_always_true
});
expect(result).not.toContain('always false');
});
});
test('should not touch other expressions', () => {
const newLocal = ` {% if (myval==='some_setting_always_true' | setting) %} always true {% else %} always false{% endif %}
`;
[0, undefined, '', false, -0, null, NaN, ``, '', true, 1, {}, [], '0'].forEach(some_setting_always_true => {
const result = precompile(newLocal, {}, [], {
some_setting_always_true
});
expect(result).toContain('always false');
expect(result).toContain('always true');
});
});
});
const { default: traverse } = require('@babel/traverse');
const t = require('@babel/types');
const isFalsyLiteral = test =>
(t.isBooleanLiteral(test) && !test.value) ||
(t.isNumericLiteral(test) && !test.value) ||
(t.isStringLiteral(test) && !test.value) ||
t.isNullLiteral(test) ||
(t.isIdentifier(test) && test.name === 'undefined');
const isTruthyLiteral = test =>
t.isObjectExpression(test) ||
t.isArrayExpression(test) ||
(t.isStringLiteral(test) && test.value) ||
(t.isBooleanLiteral(test) && test.value) ||
(t.isNumericLiteral(test) && test.value);
module.exports = function replaceLiteralValuesInTemplate(program) {
traverse(program, {
ConditionalExpression(path) {
let test = path.node.test;
if (t.isSequenceExpression(test) && test.expressions.length === 1) {
test = test.expressions[0];
}
if (isTruthyLiteral(test)) {
path.replaceWith(path.node.consequent);
} else if (isFalsyLiteral(test)) {
path.replaceWith(path.node.alternate);
}
},
TemplateLiteral(path) {

@@ -7,0 +33,0 @@ if (!path.node.expressions.some(it => t.isStringLiteral(it))) return;

24

package.json
{
"name": "@ordergroove/smi-precompile",
"version": "1.6.1",
"version": "1.6.2-alpha-PR-542-24.329+9aab0a3e",
"description": "Prcompilers for smi-core",

@@ -15,10 +15,17 @@ "author": "Brian Lewis <brian.lewis@ordergroove.com>",

"scripts": {
"start": "../../node_modules/.bin/webpack-dev-server --mode development",
"build": "rm -rf dist && ../../node_modules/.bin/webpack --mode development",
"build:prod": "rm -rf dist && ../../node_modules/.bin/webpack --mode production --display errors-only",
"start": "npm run build -- --serve",
"build": "rm -rf dist && node build",
"build:prod": "npm run build -- --prod",
"test": "../../node_modules/.bin/jest --ci --silent",
"test:watch": "../../node_modules/.bin/jest --watch",
"prepublishOnly": "npm run -s lint && npm run -s test && npm run -s build:prod",
"bundlesize": "../../node_modules/.bin/bundlesize",
"prepublishOnly": "npm run -s build:prod",
"lint": "../../node_modules/.bin/eslint --ignore-path ../../.gitignore ./src"
},
"bundlesize": [
{
"path": "./dist/smi-precompile.js",
"maxSize": "380 kB"
}
],
"bugs": {

@@ -34,3 +41,3 @@ "url": "https://github.com/ordergroove/plush-toys/issues"

"@babel/types": "^7.13.0",
"@ordergroove/i18n-data": "^0.3.0",
"@ordergroove/i18n-data": "^0.3.1-alpha-PR-542-24.370+9aab0a3e",
"glob": "^7.1.6",

@@ -41,3 +48,6 @@ "less": "^4.1.1",

},
"gitHead": "36347117970d3062dc66f31e4af5a8e1084a16fd"
"devDependencies": {
"path-browserify": "^1.0.1"
},
"gitHead": "9aab0a3e8444d3a178d5ade8e92b7843d84991ab"
}

Sorry, the diff of this file is not supported yet

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

Sorry, the diff of this file is not supported yet

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