Skip to content

Commit 2d988a6

Browse files
committed
add .min for iife
1 parent 2b7bab3 commit 2d988a6

File tree

13 files changed

+120
-81
lines changed

13 files changed

+120
-81
lines changed

.vscode/settings.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
22
"editor.tabSize": 2,
33
"mochaExplorer.files": "test/*.js",
4-
"mochaExplorer.require": "ts-node/register",
54
}

dist/riscript.cjs

Lines changed: 58 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,46 @@
1-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var __defProp = Object.defineProperty;
1+
var __create = Object.create;
2+
var __defProp = Object.defineProperty;
3+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4+
var __getOwnPropNames = Object.getOwnPropertyNames;
5+
var __getProtoOf = Object.getPrototypeOf;
6+
var __hasOwnProp = Object.prototype.hasOwnProperty;
27
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8+
var __export = (target, all) => {
9+
for (var name in all)
10+
__defProp(target, name, { get: all[name], enumerable: true });
11+
};
12+
var __copyProps = (to, from, except, desc) => {
13+
if (from && typeof from === "object" || typeof from === "function") {
14+
for (let key of __getOwnPropNames(from))
15+
if (!__hasOwnProp.call(to, key) && key !== except)
16+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17+
}
18+
return to;
19+
};
20+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21+
// If the importer is in node compatibility mode or this is not an ESM
22+
// file that has been converted to a CommonJS file using a Babel-
23+
// compatible transform (i.e. "__esModule" has not been set), then set
24+
// "default" to the CommonJS "module.exports" for node compatibility.
25+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26+
mod
27+
));
28+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
329
var __publicField = (obj, key, value) => {
430
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
531
return value;
632
};
733

34+
// src/index.js
35+
var src_exports = {};
36+
__export(src_exports, {
37+
default: () => src_default
38+
});
39+
module.exports = __toCommonJS(src_exports);
40+
841
// src/riscript.js
9-
var _he = require('he'); var _he2 = _interopRequireDefault(_he);
10-
var _mingo = require('mingo');
42+
var import_he = __toESM(require("he"), 1);
43+
var import_mingo = require("mingo");
1144

1245
// node_modules/lodash-es/_freeGlobal.js
1346
var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
@@ -9525,11 +9558,11 @@ RootCause -> ${e}`);
95259558
this.pendingSymbols.length ? JSON.stringify(this.pendingSymbols) : ""
95269559
);
95279560
}
9528-
info = `${sym} = ${this.RiScript._escapeText(value)} [#static] ${_optionalChain([opts, 'optionalAccess', _ => _.silent]) ? "{silent}" : ""}`;
9561+
info = `${sym} = ${this.RiScript._escapeText(value)} [#static] ${opts?.silent ? "{silent}" : ""}`;
95299562
} else {
95309563
const $ = this;
95319564
value = () => $.visit(ctx.expr);
9532-
info = `${sym} = <f*:pending>` + (_optionalChain([opts, 'optionalAccess', _2 => _2.silent]) ? "{silent}" : "");
9565+
info = `${sym} = <f*:pending>` + (opts?.silent ? "{silent}" : "");
95339566
this.dynamics[ident] = value;
95349567
}
95359568
this.print("assign", info);
@@ -9601,10 +9634,10 @@ RootCause -> ${e}`);
96019634
throw Error(msg);
96029635
}
96039636
if (typeof result === "undefined") {
9604-
this.print("symbol", symbol + " -> '" + original + "' ctx=" + this.lookupsToString(), "[deferred]", _optionalChain([opts, 'optionalAccess', _3 => _3.silent]) ? "{silent}" : "");
9637+
this.print("symbol", symbol + " -> '" + original + "' ctx=" + this.lookupsToString(), "[deferred]", opts?.silent ? "{silent}" : "");
96059638
return original;
96069639
}
9607-
let info = original + " -> '" + result + "'" + (_optionalChain([opts, 'optionalAccess', _4 => _4.silent]) ? " {silent}" : "");
9640+
let info = original + " -> '" + result + "'" + (opts?.silent ? " {silent}" : "");
96089641
if (typeof result === "string" && !resolved) {
96099642
if (isStatic) {
96109643
this.pendingSymbols.add(ident);
@@ -9672,7 +9705,7 @@ RootCause -> ${e}`);
96729705
throw Error("noRepeat() not allowed on choice (use a $variable instead): " + original);
96739706
}
96749707
let decision = "accept";
9675-
if (_optionalChain([opts, 'optionalAccess', _5 => _5.forceReject])) {
9708+
if (opts?.forceReject) {
96769709
decision = "reject";
96779710
} else {
96789711
if (ctx.gate) {
@@ -9695,7 +9728,7 @@ RootCause -> ${e}`);
96959728
if (decision === "reject" && !("reject" in ctx)) {
96969729
return "";
96979730
}
9698-
const orExpr = _optionalChain([ctx, 'access', _6 => _6[decision], 'optionalAccess', _7 => _7[0], 'optionalAccess', _8 => _8.children, 'optionalAccess', _9 => _9.or_expr, 'optionalAccess', _10 => _10[0]]);
9731+
const orExpr = ctx[decision]?.[0]?.children?.or_expr?.[0];
96999732
const options = this.parseOptions(orExpr);
97009733
if (!options)
97019734
throw Error("No options in choice: " + original);
@@ -9772,7 +9805,7 @@ RootCause -> ${e}`);
97729805
}
97739806
parseOptions(ctx) {
97749807
const options = [];
9775-
if (ctx && _optionalChain([ctx, 'optionalAccess', _11 => _11.children, 'optionalAccess', _12 => _12.wexpr])) {
9808+
if (ctx && ctx?.children?.wexpr) {
97769809
const wexprs = ctx.children.wexpr;
97779810
for (let i = 0; i < wexprs.length; i++) {
97789811
const wexpr = wexprs[i];
@@ -9940,11 +9973,11 @@ RootCause -> ${e}`);
99409973
};
99419974

99429975
// src/riscript.js
9943-
var { decode } = _he2.default;
9976+
var { decode } = import_he.default;
99449977
var VowelRE = /[aeiou]/;
99459978
var RegexEscape = "_RE_";
99469979
var HtmlEntities = /&([a-z0-9]+|#[0-9]{1,6}|#x[0-9a-fA-F]{1,6});/gi;
9947-
var RiQuery = class extends _mingo.Query {
9980+
var RiQuery = class extends import_mingo.Query {
99489981
constructor(scripting, condition, options) {
99499982
if (typeof condition === "string") {
99509983
let raw = condition;
@@ -9962,7 +9995,7 @@ var RiQuery = class extends _mingo.Query {
99629995
operands() {
99639996
const stack = [this.condition];
99649997
const keys2 = /* @__PURE__ */ new Set();
9965-
while (_optionalChain([stack, 'optionalAccess', _13 => _13.length]) > 0) {
9998+
while (stack?.length > 0) {
99669999
const currentObj = stack.pop();
996710000
Object.keys(currentObj).forEach((key) => {
996810001
const value = currentObj[key];
@@ -9979,7 +10012,7 @@ var RiQuery = class extends _mingo.Query {
997910012
};
998010013
var _RiScript = class _RiScript {
998110014
static evaluate(script, context, opts = {}) {
9982-
return new _RiScript().evaluate(script, context, opts);
10015+
return new _RiScript(opts).evaluate(script, context, opts);
998310016
}
998410017
constructor(opts = {}) {
998510018
this.visitor = 0;
@@ -10190,7 +10223,7 @@ Final: '${result}'`);
1019010223
if (!s || !s.length)
1019110224
return "";
1019210225
let first2 = s.split(/\s+/)[0];
10193-
if (!_optionalChain([_RiScript, 'access', _14 => _14.RiTa, 'optionalAccess', _15 => _15.phones])) {
10226+
if (!_RiScript.RiTa?.phones) {
1019410227
if (!_RiScript.RiTaWarnings.phones) {
1019510228
console.warn("[WARN] Install RiTa for proper phonemes");
1019610229
_RiScript.RiTaWarnings.phones = true;
@@ -10214,7 +10247,7 @@ Final: '${result}'`);
1021410247
}
1021510248
// Default transform that pluralizes a string (requires RiTa)
1021610249
static pluralize(s) {
10217-
if (!_optionalChain([_RiScript, 'access', _16 => _16.RiTa, 'optionalAccess', _17 => _17.pluralize])) {
10250+
if (!_RiScript.RiTa?.pluralize) {
1021810251
if (!_RiScript.RiTaWarnings.plurals) {
1021910252
_RiScript.RiTaWarnings.plurals = true;
1022010253
console.warn("[WARN] Install RiTa for proper pluralization");
@@ -10255,7 +10288,7 @@ Final: '${result}'`);
1025510288
}
1025610289
};
1025710290
__publicField(_RiScript, "Query", RiQuery);
10258-
__publicField(_RiScript, "VERSION", "1.0.20");
10291+
__publicField(_RiScript, "VERSION", "1.0.21");
1025910292
__publicField(_RiScript, "RiTaWarnings", { plurals: false, phones: false });
1026010293
var RiScript = _RiScript;
1026110294
RiScript.transforms = {
@@ -10307,6 +10340,9 @@ function charCount(str, c) {
1030710340
// src/grammar.js
1030810341
var RiGrammar = class _RiGrammar {
1030910342
constructor(rules = {}, context = {}) {
10343+
if (typeof rules === "string") {
10344+
rules = parseJSON(rules);
10345+
}
1031010346
if (typeof rules !== "object") {
1031110347
throw Error("RiGrammar: expecting object, found " + typeof rules);
1031210348
}
@@ -10341,14 +10377,15 @@ var RiGrammar = class _RiGrammar {
1034110377
addRule(name, def) {
1034210378
this._validateRule(name, def);
1034310379
this.rules[name] = def;
10380+
return this;
1034410381
}
1034510382
setRules(rules) {
1034610383
if (typeof rules === "undefined")
1034710384
throw Error("undefined rules");
1034810385
this.rules = {};
1034910386
let incoming = typeof rules === "string" ? parseJSON(rules) : rules;
10350-
let self2 = this;
10351-
Object.entries(incoming).forEach((e) => self2.addRule(...e));
10387+
Object.entries(incoming).forEach((e) => this.addRule(...e));
10388+
return this;
1035210389
}
1035310390
removeRule(name) {
1035410391
if (name in this.rules) {
@@ -10361,7 +10398,7 @@ var RiGrammar = class _RiGrammar {
1036110398
toString(opts = {}) {
1036210399
let replacer = opts.replacer || 0;
1036310400
let space = opts.space || 2;
10364-
let lb = _optionalChain([opts, 'optionalAccess', _18 => _18.linebreak]);
10401+
let lb = opts?.linebreak;
1036510402
let res = this.toJSON(replacer, space);
1036610403
if (lb)
1036710404
res = res.replace(/\n/g, lb);
@@ -10436,9 +10473,6 @@ function parseJSON(json) {
1043610473
RiScript.Grammar = RiGrammar;
1043710474
RiScript.Visitor = RiScriptVisitor;
1043810475
var src_default = RiScript;
10439-
10440-
10441-
exports.default = src_default;
1044210476
/*! Bundled license information:
1044310477
1044410478
lodash-es/lodash.js:
@@ -10452,5 +10486,4 @@ lodash-es/lodash.js:
1045210486
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
1045310487
*)
1045410488
*/
10455-
10456-
module.exports = exports.default//# sourceMappingURL=riscript.cjs.map
10489+
//# sourceMappingURL=riscript.cjs.map

dist/riscript.cjs.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/riscript.iife.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 30 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/riscript.iife.min.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/riscript.js

Lines changed: 8 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/riscript.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/grammar.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import { RiScript } from './riscript.js'
33
class RiGrammar {
44

55
constructor(rules = {}, context = {}) {
6+
if (typeof rules === 'string') {
7+
rules = parseJSON(rules);
8+
}
9+
610
if (typeof rules !== 'object') {
711
throw Error('RiGrammar: expecting object, found ' + typeof rules);
812
}
@@ -39,22 +43,22 @@ class RiGrammar {
3943
opts.visitor = opts.visitor || new RiScript.Visitor(this.scripting);
4044
opts.visitor.context = this.context || {};
4145
opts.input = this._toScript(opts);
42-
// opts.noAddedSilence = true;
4346

4447
return this.scripting._evaluate(opts);
4548
}
4649

4750
addRule(name, def) {
4851
this._validateRule(name, def);
4952
this.rules[name] = def;
53+
return this;
5054
}
5155

5256
setRules(rules) {
5357
if (typeof rules === 'undefined') throw Error('undefined rules');
5458
this.rules = {};
5559
let incoming = typeof rules === 'string' ? parseJSON(rules) : rules;
56-
let self = this;
57-
Object.entries(incoming).forEach((e) => self.addRule(...e));
60+
Object.entries(incoming).forEach((e) => this.addRule(...e));
61+
return this;
5862
}
5963

6064
removeRule(name) {

src/riscript.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class RiScript {
6969
static RiTaWarnings = { plurals: false, phones: false };
7070

7171
static evaluate(script, context, opts = {}) {
72-
return new RiScript().evaluate(script, context, opts);
72+
return new RiScript(opts).evaluate(script, context, opts);
7373
}
7474

7575
constructor(opts = {}) { // private ?

0 commit comments

Comments
 (0)