fable 3.1.47 → 3.1.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fable",
3
- "version": "3.1.47",
3
+ "version": "3.1.49",
4
4
  "description": "A service dependency injection, configuration and logging library.",
5
5
  "main": "source/Fable.js",
6
6
  "scripts": {
@@ -28,7 +28,7 @@ class ExpressionParserOperationBase extends libFableServiceProviderBase
28
28
  {
29
29
  return 'Token.StateAddress';
30
30
  }
31
- else if ((pToken.length > 2) && (pToken[0] === '"') && (pToken[pToken.length-1] === '"'))
31
+ else if ((pToken.length > 1) && (pToken[0] === '"') && (pToken[pToken.length-1] === '"'))
32
32
  {
33
33
  return 'Token.String';
34
34
  }
@@ -39,6 +39,7 @@ class ExpressionTokenizer extends libExpressionParserOperationBase
39
39
  * - String
40
40
  * : Wrapped in double quotes e.g. "Hello World", "This is a test", etc.
41
41
  */
42
+ /** @type {any} */
42
43
  let tmpCurrentTokenType = false;
43
44
  let tmpCurrentToken = '';
44
45
  for (let i = 0; i < pExpression.length; i++)
@@ -213,4 +214,4 @@ class ExpressionTokenizer extends libExpressionParserOperationBase
213
214
  }
214
215
  }
215
216
 
216
- module.exports = ExpressionTokenizer;
217
+ module.exports = ExpressionTokenizer;
@@ -63,7 +63,7 @@ class ExpressionParserValueMarshal extends libExpressionParserOperationBase
63
63
  tmpToken.Value = tmpValue;
64
64
  tmpToken.Resolve = true;
65
65
  tmpResults.ExpressionParserLog.push(`WARNING: ExpressionParser.substituteValuesInTokenizedObjects found no value for the symbol hash or address ${tmpToken.Token} at index ${i}`);
66
- this.log.warn(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);
66
+ if (this.LogNoisiness > 1) this.log.warn(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);
67
67
  continue;
68
68
  }
69
69
  else
@@ -110,13 +110,13 @@ class ExpressionParserValueMarshal extends libExpressionParserOperationBase
110
110
  if (!tmpValue)
111
111
  {
112
112
  tmpResults.ExpressionParserLog.push(`WARNING: ExpressionParser.substituteValuesInTokenizedObjects found no value for the state address ${tmpToken.Token} at index ${i}`);
113
- this.log.warn(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);
113
+ //this.log.warn(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);
114
114
  continue;
115
115
  }
116
116
  else
117
117
  {
118
118
  //tmpResults.ExpressionParserLog.push(`INFO: ExpressionParser.substituteValuesInTokenizedObjects found a value [${tmpValue}] for the state address ${tmpToken.Token} at index ${i}`);
119
- this.log.info(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);
119
+ //this.log.info(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);
120
120
  try
121
121
  {
122
122
  let tmpValueParsed = new this.fable.Utility.bigNumber(tmpValue);
@@ -190,6 +190,28 @@ class FableServiceExpressionParser extends libFableServiceBase
190
190
  return this.Solver.solvePostfixedExpression(pPostfixedExpression, pDataDestinationObject, pResultObject, pManifest);
191
191
  }
192
192
 
193
+ /**
194
+ * Add a function to the solver.
195
+ *
196
+ * @param {string} pFunctionName
197
+ * @param {string} pFunctionAddress
198
+ * @param {string} pFunctionComment
199
+ */
200
+ addSolverFunction(pFunctionName, pFunctionAddress, pFunctionComment)
201
+ {
202
+ let tmpFunctionName = (pFunctionName || '').trim().toLowerCase();
203
+ if (this.functionMap.hasOwnProperty(tmpFunctionName))
204
+ {
205
+ this.log.warn(`PictDynamicFormsInformary: Function ${tmpFunctionName} already exists in the solver, overwriting with address [${pFunctionAddress}].`);
206
+ //return false;
207
+ }
208
+ this.functionMap[tmpFunctionName] = (
209
+ {
210
+ Name: pFunctionComment || `Autogenerated function ${tmpFunctionName}`,
211
+ Address: pFunctionAddress,
212
+ });
213
+ }
214
+
193
215
  /**
194
216
  * Prepares the parameters for a SERIES directive by substituting values and applying defaults.
195
217
  *
@@ -919,6 +919,68 @@ suite
919
919
  }
920
920
  );
921
921
 
922
+ test('Solver Quoted Empty Strings', () =>
923
+ {
924
+ const tmpSourceData =
925
+ {
926
+ };
927
+ let testFable = new libFable();
928
+ let _Parser = testFable.instantiateServiceProviderIfNotExists('ExpressionParser');
929
+
930
+ let tmpSolverResults = {};
931
+
932
+ _Parser.solve('Taco = 3', tmpSourceData, {}, false, tmpSourceData);
933
+ Expect(tmpSourceData.Taco).to.equal('3');
934
+
935
+ _Parser.solve('Taco = ""', tmpSourceData, tmpSolverResults, false, tmpSourceData);
936
+ Expect(tmpSourceData.Taco).to.equal('');
937
+
938
+ Expect(_Parser.solve('Taco = " "', tmpSourceData, tmpSolverResults, false, tmpSourceData)).to.equal(' ');
939
+ Expect(_Parser.solve('Taco = "Whooo"', tmpSourceData, tmpSolverResults, false, tmpSourceData)).to.equal('Whooo');
940
+ });
941
+ test('Solver Performance', () =>
942
+ {
943
+ const tmpSourceData =
944
+ {
945
+ MethodAB_WWD_Dry_MinMoistureContent: -150,
946
+ MethodAB_WWD_Dry_MaxMoistureContent: -18.3,
947
+ };
948
+ const tmpExpr = 'MethodAB_WWD_Dry_PlotXValues = SERIES FROM MethodAB_WWD_Dry_MinMoistureContent TO MethodAB_WWD_Dry_MaxMoistureContent STEP 0.1 : n + 0';
949
+ let testFable = new libFable();
950
+ let _Parser = testFable.instantiateServiceProviderIfNotExists('ExpressionParser');
951
+
952
+ const t0 = performance.now();
953
+ // Execute the expression multiple times to get a measurable time
954
+ _Parser.solve(tmpExpr, tmpSourceData, {}, false, tmpSourceData);
955
+ const t1 = performance.now();
956
+ const duration = t1 - t0;
957
+ testFable.log.info(`Solver Performance Test: Executed in ${duration} milliseconds.`);
958
+ Expect(tmpSourceData.MethodAB_WWD_Dry_PlotXValues.length).to.equal(1318);
959
+ Expect(tmpSourceData.MethodAB_WWD_Dry_PlotXValues[0]).to.equal('-150');
960
+ Expect(tmpSourceData.MethodAB_WWD_Dry_PlotXValues[1317]).to.equal('-18.3');
961
+ Expect(duration).to.be.below(100);
962
+ });
963
+ test
964
+ (
965
+ 'Custom Solver Functions',
966
+ (fNext) =>
967
+ {
968
+ let testFable = new libFable();
969
+
970
+ testFable.MonkeyFunction = (pParameter) => { return `Monkey says hello to ${pParameter}`; };
971
+
972
+ let _Parser = testFable.instantiateServiceProviderIfNotExists('ExpressionParser');
973
+ let tmpResultsObject = {};
974
+ let tmpDestinationObject = {};
975
+
976
+ _Parser.addSolverFunction('monkeypatchedfunction', 'fable.MonkeyFunction', 'This is just for documentation.');
977
+
978
+ _Parser.solve('MonkeyResult = monkeypatchedfunction("Jerry")', testFable, tmpResultsObject, false, tmpDestinationObject);
979
+ Expect(tmpDestinationObject.MonkeyResult).to.equal('Monkey says hello to Jerry');
980
+ return fNext();
981
+ }
982
+ );
983
+
922
984
  test
923
985
  (
924
986
  'Series + Regression',