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 ;
27var __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 ) ;
329var __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
1346var 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 ;
99449977var VowelRE = / [ a e i o u ] / ;
99459978var RegexEscape = "_RE_" ;
99469979var HtmlEntities = / & ( [ a - z 0 - 9 ] + | # [ 0 - 9 ] { 1 , 6 } | # x [ 0 - 9 a - f A - 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} ;
998010013var _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 } ) ;
1026010293var RiScript = _RiScript ;
1026110294RiScript . transforms = {
@@ -10307,6 +10340,9 @@ function charCount(str, c) {
1030710340// src/grammar.js
1030810341var 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) {
1043610473RiScript . Grammar = RiGrammar ;
1043710474RiScript . Visitor = RiScriptVisitor ;
1043810475var src_default = RiScript ;
10439-
10440-
10441- exports . default = src_default ;
1044210476/*! Bundled license information:
1044310477
1044410478lodash-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
0 commit comments