コード例 #1
0
 inspectedObjects: function() {
   return inspectedObjectLiteral(
     `<UniqueIdentifierHandle preferredName: '${Caf.toString(
       this.preferredName
     )}', scopeSet: ${Caf.toString(
       !!this.scope
     )}, _identifier: ${Caf.toString(inspect(this._identifier))}>`
   );
 },
コード例 #2
0
 (initializer, identifier) =>
   isString(initializer)
     ? `${Caf.toString(identifier)} = ${Caf.toString(
         initializer
       )}`
     : initializer.toJsExpression != null
     ? `${Caf.toString(identifier)} = ${Caf.toString(
         initializer.toJsExpression()
       )}`
     : identifier,
コード例 #3
0
 (() => {
   while (
     blockedIndentifiers[
       (name = `${Caf.toString(preferredName)}${Caf.toString(
         (count += 1)
       )}`)
     ]
   ) {
     name;
   }
 })(),
コード例 #4
0
 this.resolveOperatorPrecidence = (
   operators,
   operands,
   combinerOverride
 ) => {
   if (!(operands.length === operators.length + 1)) {
     throw new Error(
       `expecting: operands.length:${Caf.toString(
         operands.length
       )} == operators.length:${Caf.toString(operators.length)} + 1`
     );
   }
   while (operators.length > 0) {
     let lowestPrecidence,
       firstOccurance,
       lastOccurance,
       p,
       opIndexToResolve,
       opsBefore,
       operandsBefore,
       op,
       operandA,
       operandB,
       combiner;
     lowestPrecidence = this.getOpPrecidence(operators[0]);
     firstOccurance = lastOccurance = 0;
     p = null;
     Caf.each2(operators, (op, i) =>
       lowestPrecidence > (p = this.getOpPrecidence(op))
         ? ((firstOccurance = lastOccurance = i),
           (lowestPrecidence = p))
         : lowestPrecidence === p
         ? (lastOccurance = i)
         : undefined
     );
     opIndexToResolve = this.getPrecidenceLevelIsLeftAssociative(p)
       ? firstOccurance
       : lastOccurance;
     opsBefore = operators;
     operandsBefore = operands;
     op = operators[opIndexToResolve];
     operandA = operands[opIndexToResolve];
     operandB = operands[opIndexToResolve + 1];
     operators = arrayWithout(operators, opIndexToResolve);
     operands = arrayWithout(operands, opIndexToResolve);
     combiner = combinerOverride || this.operatorMap[op] || infix;
     operands[opIndexToResolve] = combiner(operandA, operandB, op);
   }
   if (!(operands.length === 1)) {
     throw new Error();
   }
   return operands[0];
 };
コード例 #5
0
 return (() => {
   throw new Error(
     `toSourceNode not overridden in ${Caf.toString(
       this.class.name
     )}. Falling back to old toJs().`
   );
 })();
コード例 #6
0
 ? (() => {
     throw new Error(
       `Scope must be fully updated. ${Caf.toString(
         this.className
       )}`
     );
   })()
コード例 #7
0
 autoLets: function() {
   let identifiers;
   this.bindAllUniqueIdentifiersRequested();
   return this._identifiersAssigned &&
     (identifiers = this.requiredIdentifierLets).length > 0
     ? `let ${Caf.toString(identifiers.join(", "))}`
     : undefined;
 }
コード例 #8
0
 this.getOpPrecidence = op => {
   let p;
   if (!((p = this.opsToPrecidence[op]) != null)) {
     throw new Error(
       `OperatorHelper: operator '${Caf.toString(op)}' not defined`
     );
   }
   return p;
 };
コード例 #9
0
 this.validateOperator = validateOperator = operator => {
   if (!this.opsToPrecidence[operator]) {
     throw new Error(
       `OperatorHelper: operator '${Caf.toString(
         operator
       )}' is not defined`
     );
   }
   return operator;
 };
コード例 #10
0
 inspectedObjects: function() {
   let label, props, name, a;
   ({ label } = this);
   props = this.getInspectedProps();
   name = this.class.getName();
   if (label) {
     name = `${Caf.toString(label)}.${Caf.toString(name)}`;
   }
   return {
     [`${Caf.toString(name)}`]:
       this.children.length === 0
         ? toInspectedObjects(props)
         : ((a = []),
           objectKeyCount(props) > 0 ? a.push(props) : undefined,
           a.concat(
             Caf.array(this.children, c => c.inspectedObjects)
           ))
   };
 },
コード例 #11
0
 this.prototype.toSourceNode = function(options) {
   let out;
   out = supportedOperatorsRegExp.test(this.operator)
     ? this.createSourceNode(
         this.lValue.toSourceNode(),
         ` ${Caf.toString(this.operator)}= `,
         this.rValue.toSourceNode({ expression: true })
       )
     : this.createSourceNode(
         this.lValue.toSourceNode({ expression: true }),
         ` ${Caf.toString(this.operator)} `,
         this.lValue.toSourceNode(),
         " = ",
         this.rValue.toSourceNode({ expression: true })
       );
   return (Caf.exists(options) && options.dotBase) ||
     (Caf.exists(options) && options.subExpression)
     ? this.createSourceNode("(", out, ")")
     : out;
 };
コード例 #12
0
 this.prototype.getBareInitializers = function() {
   let identifiers;
   this.bindAllUniqueIdentifiersRequested();
   return this._identifiersAssigned &&
     (identifiers = this.requiredIdentifierLets).length > 0
     ? ((identifiers = Caf.array(identifiers, null, identifier =>
         identifier.match(/=/)
       )),
       identifiers.length > 0
         ? `${Caf.toString(identifiers.join("; "))}`
         : undefined)
     : undefined;
 };
コード例 #13
0
 "?": function(a, b) {
   return a.match(/^@?[_a-z0-9]+$/i)
     ? `${Caf.toString(a)} != null ? ${Caf.toString(
         a
       )} : ${Caf.toString(b)}`
     : `${Caf.toString(CoffeeScriptGlobal)}.existsOr(${Caf.toString(
         a
       )}, (() => {return ${Caf.toString(b)}})())`;
 }
コード例 #14
0
 constructor(props, children) {
   super(...arguments);
   this.operator = props.operator || "";
   this.lValue = children[0];
   this.rValue = children[1];
   if (!(this.lValue && this.rValue)) {
     throw new Error(
       `AssignmentStn: expected lValue and rValue: ${Caf.toString(
         formattedInspect({
           operator: this.operator,
           lValue: this.lValue,
           rValue: this.rValue
         })
       )}`
     );
   }
 }
コード例 #15
0
 this.infix = infix = function(a, b, op) {
   return `${Caf.toString(a)} ${Caf.toString(op)} ${Caf.toString(b)}`;
 };
コード例 #16
0
 isnt: function(a, b) {
   return `!${Caf.toString(CoffeeScriptGlobal)}.is(${Caf.toString(
     a
   )}, ${Caf.toString(b)})`;
 },
コード例 #17
0
 "%%": function(a, b) {
   return `${Caf.toString(CoffeeScriptGlobal)}.mod(${Caf.toString(
     a
   )}, ${Caf.toString(b)})`;
 },
コード例 #18
0
 return function() {
   this.rule({
     doubleQuote: /"/,
     singleQuote: /'/,
     interpolationStart: /\#\{/,
     interpolationEnd: /\}/,
     dqStringMiddle: /([^"\\#]|\u[0-9a-f]{4}|\u\{[0-9a-f]+\}|\x[0-9a-f]{2}|\\(?:[1-7][0-7]{0,2}|[0-7]{2,3})|\\.|\#(?!\{))*/,
     sqStringMiddle: /([^'\\#]|\u[0-9a-f]{4}|\u\{[0-9a-f]+\}|\x[0-9a-f]{2}|\\(?:[1-7][0-7]{0,2}|[0-7]{2,3})|\\.|\#(?!\{))*/,
     blockStringMiddle: /([^\\#]|\u[0-9a-f]{4}|\u\{[0-9a-f]+\}|\x[0-9a-f]{2}|\\(?:[1-7][0-7]{0,2}|[0-7]{2,3})|\\.|\#(?!\{))*/
   });
   this.rule({
     stringLiteral: [
       {
         pattern: `/""/ tripple:/"/? &/${Caf.toString(
           blockStringStartChar.source
         )}/ stringBlock`,
         getStn: function() {
           let ret;
           ret = this.stringBlock.getStn();
           if (!this.tripple) {
             Caf.isF(ret.compactNewLines) && ret.compactNewLines();
             Caf.isF(ret.trimLeft) && ret.trimLeft();
           }
           Caf.isF(ret.trimRight) && ret.trimRight();
           return ret;
         }
       },
       {
         pattern: "/''/ tripple:/'/? &/ +[^ \\n]| *\\n/ unparsedBlock",
         getStn: function() {
           let ret;
           ret = StringStn({
             parseTreeNode: this,
             value: this.unparsedBlock.toString()
           });
           if (!this.tripple) {
             ret.compactNewLines();
           }
           return ret;
         }
       },
       {
         pattern: "/\"\"\"|'''/",
         getStn: function() {
           return StringStn({ parseTreeNode: this, value: "" });
         }
       },
       {
         pattern: RegExp(`:(?!:)${Caf.toString(wordStringChar.source)}+`),
         getStn: function() {
           return StringStn({
             parseTreeNode: this,
             value: this.toString().slice(1)
           });
         }
       },
       {
         pattern: /#[$\w\u007f-\uffff]+/,
         getStn: function() {
           return StringStn({
             parseTreeNode: this,
             value: this.toString()
           });
         }
       },
       {
         pattern: /[-+]?(?!00)[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?[$\w\u007f-\uffff]+/,
         getStn: function() {
           return StringStn({
             parseTreeNode: this,
             value: this.toString()
           });
         }
       }
     ],
     stringBlock: Extensions.IndentBlocks.getPropsToSubparseToEolAndBlock({
       rule: "stringBlockBody"
     })
   });
   this.rule(
     {
       stringLiteral: [
         "bracketStart:doubleQuote mid:dqStringMiddle interpolation:dqStringInterpolation? doubleQuote",
         "bracketStart:singleQuote mid:sqStringMiddle interpolation:sqStringInterpolation? singleQuote"
       ],
       stringBlockBody:
         "/ *\n/? mid:blockStringMiddle interpolation:blockStringInterpolation?"
     },
     {
       getStnChildren: function(appendTo = []) {
         let base;
         if (this.mid.matchLength > 0) {
           appendTo.push(
             StringStn({ parseTreeNode: this, value: this.mid.toString() })
           );
         }
         Caf.exists((base = this.interpolation)) &&
           base.getStnChildren(appendTo);
         return appendTo;
       },
       getStn: function() {
         let ret;
         ret = this.interpolation
           ? InterpolatedStringStn(this.getStnChildren())
           : StringStn({
               parseTreeNode: this,
               value: this.mid.toString()
             });
         if (this.bracketStart) {
           ret.compactNewLines(true, true);
         }
         return ret;
       }
     }
   );
   this.rule({
     interpolation: [
       "interpolationStart interpolationEnd expression:toEolAndBlock",
       "interpolationStart _OrEnd interpolationEnd",
       "interpolationStart _? expression:root interpolationEnd",
       "interpolationStart expression:block end? interpolationEnd"
     ]
   });
   return this.rule(
     {
       dqStringInterpolation:
         "interpolation mid:dqStringMiddle interpolationContinues:dqStringInterpolation?",
       sqStringInterpolation:
         "interpolation mid:sqStringMiddle interpolationContinues:sqStringInterpolation?",
       blockStringInterpolation:
         "interpolation mid:blockStringMiddle interpolationContinues:blockStringInterpolation?"
     },
     {
       getStnChildren: function(appendTo = []) {
         let expression, base;
         if ((expression = this.interpolation.expression)) {
           appendTo.push(expression.getStn());
         }
         if (this.mid.matchLength > 0) {
           appendTo.push(
             StringStn({ parseTreeNode: this, value: this.mid.toString() })
           );
         }
         Caf.exists((base = this.interpolationContinues)) &&
           base.getStnChildren(appendTo);
         return appendTo;
       }
     }
   );
 };
コード例 #19
0
 return (() => {
   switch (operand) {
     case "**":
       return [
         `${Caf.toString(CoffeeScriptGlobal)}.pow(`,
         a,
         ", ",
         b,
         ")"
       ];
     case "//":
       return [
         `${Caf.toString(CoffeeScriptGlobal)}.div(`,
         a,
         ", ",
         b,
         ")"
       ];
     case "%%":
       return [
         `${Caf.toString(CoffeeScriptGlobal)}.mod(`,
         a,
         ", ",
         b,
         ")"
       ];
     case "in":
       return [
         `${Caf.toString(CoffeeScriptGlobal)}.in(`,
         a,
         ", ",
         b,
         ")"
       ];
     case "is":
       return [
         `${Caf.toString(CoffeeScriptGlobal)}.is(`,
         a,
         ", ",
         b,
         ")"
       ];
     case "isnt":
       return [
         `!${Caf.toString(CoffeeScriptGlobal)}.is(`,
         a,
         ", ",
         b,
         ")"
       ];
     case "?":
       return (() => {
         switch (aStn.type) {
           case "This":
           case "Identifier":
           case "Reference":
             return [a, " != null ? ", a, " : ", b];
           default:
             return [
               CoffeeScriptGlobal,
               ".existsOr(",
               a,
               ", (() => {return ",
               b,
               "})())"
             ];
         }
       })();
     default:
       return [a, ` ${Caf.toString(operand)} `, b];
   }
 })();