From f910e6834cb544850b25960629d7bd29dd1a3c1e Mon Sep 17 00:00:00 2001 From: Dmitry Iv Date: Mon, 30 Jan 2023 07:51:53 -0500 Subject: [PATCH] Turn into module, use justin --- index.js | 18 +++++++++--------- package-lock.json | 43 ++++++++++++------------------------------- package.json | 5 +++-- test.js | 9 ++++----- 4 files changed, 28 insertions(+), 47 deletions(-) diff --git a/index.js b/index.js index 1fa7d7d..6b9bf6f 100644 --- a/index.js +++ b/index.js @@ -3,12 +3,12 @@ * @module prepr */ -var paren = require('parenthesis'); -var balanced = require('balanced-match'); -var extend = require('object-assign'); -var escaper = require('escaper'); -var ee = require('expression-eval'); -var stripComments = require('strip-json-comments') +import paren from 'parenthesis'; +import balanced from 'balanced-match'; +import extend from 'object-assign'; +import escaper from 'escaper'; +import createFn from 'subscript/justin.js'; +import stripComments from 'strip-json-comments'; /** @@ -313,8 +313,8 @@ function preprocess (what, how) { expr = stripComments(process(expr)); try { - var expr = ee.parse(expr); - result = ee.eval(expr, macros); + var evaluate = createFn(expr); + result = evaluate(expr, macros); } catch (e) { result = false; } @@ -341,4 +341,4 @@ function preprocess (what, how) { } -module.exports = preprocess; +export default preprocess; \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 7916ae7..de49c0d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,10 +11,10 @@ "dependencies": { "balanced-match": "^2.0.0", "escaper": "^2.5.3", - "expression-eval": "^5.0.0", "object-assign": "^4.1.1", "parenthesis": "^3.1.8", - "strip-json-comments": "^3.1.1" + "strip-json-comments": "^3.1.1", + "subscript": "^7.3.1" }, "devDependencies": { "cln": "^1.1.0", @@ -216,14 +216,6 @@ "resolved": "https://registry.npmjs.org/escaper/-/escaper-2.5.3.tgz", "integrity": "sha512-QGb9sFxBVpbzMggrKTX0ry1oiI4CSDAl9vIL702hzl1jGW8VZs7qfqTRX7WDOjoNDoEVGcEtu1ZOQgReSfT2kQ==" }, - "node_modules/expression-eval": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/expression-eval/-/expression-eval-5.0.0.tgz", - "integrity": "sha512-2H7OBTa/UKBgTVRRb3/lXd+D89cLjClNtldnzOpZYWZK1zBLIlrz8BLWp5f81AAYOc37GbhkCRXtl5Z/q4D91g==", - "dependencies": { - "jsep": "^0.3.0" - } - }, "node_modules/for-each": { "version": "0.3.3", "resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz", @@ -664,14 +656,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/jsep": { - "version": "0.3.5", - "resolved": "https://registry.npmjs.org/jsep/-/jsep-0.3.5.tgz", - "integrity": "sha512-AoRLBDc6JNnKjNcmonituEABS5bcfqDhQAWWXNTFrqu6nVXBpBAGfcoTGZMFlIrh9FjmE1CQyX9CTNwZrXMMDA==", - "engines": { - "node": ">= 6.0.0" - } - }, "node_modules/minimatch": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", @@ -909,6 +893,11 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/subscript": { + "version": "7.3.1", + "resolved": "https://registry.npmjs.org/subscript/-/subscript-7.3.1.tgz", + "integrity": "sha512-6GhrvO2MTQU+o099BCzAQFcXE2z76FapKPdQdDe1bkMRzTqcMOkU+BMbdIdzWPPATqu3hNu/AyTiRDFSP0rqYw==" + }, "node_modules/supports-preserve-symlinks-flag": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", @@ -1187,14 +1176,6 @@ "resolved": "https://registry.npmjs.org/escaper/-/escaper-2.5.3.tgz", "integrity": "sha512-QGb9sFxBVpbzMggrKTX0ry1oiI4CSDAl9vIL702hzl1jGW8VZs7qfqTRX7WDOjoNDoEVGcEtu1ZOQgReSfT2kQ==" }, - "expression-eval": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/expression-eval/-/expression-eval-5.0.0.tgz", - "integrity": "sha512-2H7OBTa/UKBgTVRRb3/lXd+D89cLjClNtldnzOpZYWZK1zBLIlrz8BLWp5f81AAYOc37GbhkCRXtl5Z/q4D91g==", - "requires": { - "jsep": "^0.3.0" - } - }, "for-each": { "version": "0.3.3", "resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz", @@ -1497,11 +1478,6 @@ "call-bind": "^1.0.2" } }, - "jsep": { - "version": "0.3.5", - "resolved": "https://registry.npmjs.org/jsep/-/jsep-0.3.5.tgz", - "integrity": "sha512-AoRLBDc6JNnKjNcmonituEABS5bcfqDhQAWWXNTFrqu6nVXBpBAGfcoTGZMFlIrh9FjmE1CQyX9CTNwZrXMMDA==" - }, "minimatch": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", @@ -1673,6 +1649,11 @@ "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==" }, + "subscript": { + "version": "7.3.1", + "resolved": "https://registry.npmjs.org/subscript/-/subscript-7.3.1.tgz", + "integrity": "sha512-6GhrvO2MTQU+o099BCzAQFcXE2z76FapKPdQdDe1bkMRzTqcMOkU+BMbdIdzWPPATqu3hNu/AyTiRDFSP0rqYw==" + }, "supports-preserve-symlinks-flag": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", diff --git a/package.json b/package.json index 2df533f..cb2983f 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "1.2.5", "description": "Preprocess string in C/GLSL-preprocessor fashion", "main": "index.js", + "type": "module", "scripts": { "test": "node test.js", "test:browser": "budo test.js" @@ -36,9 +37,9 @@ "dependencies": { "balanced-match": "^2.0.0", "escaper": "^2.5.3", - "expression-eval": "^5.0.0", "object-assign": "^4.1.1", "parenthesis": "^3.1.8", - "strip-json-comments": "^3.1.1" + "strip-json-comments": "^3.1.1", + "subscript": "^7.3.1" } } diff --git a/test.js b/test.js index 1509155..69480f9 100644 --- a/test.js +++ b/test.js @@ -1,7 +1,7 @@ -var test = require('tape'); -var prepr = require('./'); -var clean = require('cln'); -var assert = require('assert'); +import test from 'tape'; +import prepr from './index.js'; +import clean from 'cln'; +import assert from 'assert'; test('Object macros', function (t) { t.equal(clean(prepr(` @@ -573,7 +573,6 @@ test('Real use-case', function (t) { test('Too many comments', function (t) { - var escaper = require('escaper') var src = ` /* a */ // b