Skip to content

Commit

Permalink
FIX: .123 line-start-bug
Browse files Browse the repository at this point in the history
  • Loading branch information
shanebdavis committed Nov 17, 2018
1 parent 3f3e575 commit 1a2da83
Show file tree
Hide file tree
Showing 26 changed files with 247 additions and 245 deletions.
2 changes: 1 addition & 1 deletion cafInCaf/CaffeineScript/Rules/ControlStructures.caf
Expand Up @@ -42,7 +42,7 @@ switchWhenClause:
thenClause: "controlStructorClauseJoiner thenDo _? body:lineOfStatementsOrBlock"
elseClause: "controlStructorClauseJoiner else _? lineOfStatementsOrBlock"

controlStructorClauseJoiner: :_ :end
controlStructorClauseJoiner: "" _? end?

catch: /catch\b/
try: /try\b/
Expand Down
2 changes: 1 addition & 1 deletion cafInCaf/CaffeineScript/Rules/Statements.caf
Expand Up @@ -42,7 +42,7 @@ importBody:

newLineStatementExtension:
"end lineStartBinaryOperatorAndExpression"
"end &/\\??\\./ valueExtension+ binaryOperatorSequenceExtension?"
"end &/\\??\\.(?!\\d)/ valueExtension+ binaryOperatorSequenceExtension?"

lineOfStatements:
pattern:
Expand Down
5 changes: 2 additions & 3 deletions source/CaffeineScript/CaffeineScriptParser.js
Expand Up @@ -15,9 +15,8 @@ Caf.defMod(module, () => {
class CaffeineScriptParser extends Parser {},
function(CaffeineScriptParser, classSuper, instanceSuper) {
this.nodeBaseClass = require("./CafParseNodeBaseClass");
Caf.each2(
require("./Rules").modules,
mod => (isFunction(mod) ? mod.call(this) : this.rule(mod))
Caf.each2(require("./Rules").modules, mod =>
isFunction(mod) ? mod.call(this) : this.rule(mod)
);
this.prototype.parse = function(source, options) {
return instanceSuper.parse.call(
Expand Down
11 changes: 4 additions & 7 deletions source/CaffeineScript/Lib.js
Expand Up @@ -8,9 +8,8 @@ Caf.defMod(module, () => {
let legalUnquotedPropName;
return {
deescapeSpaces: function(string) {
return Caf.array(
string.split(/((?:\\\\)+)/),
(str, i) => (Caf.mod(i, 2) === 0 ? str.replace(/\\ /g, " ") : str)
return Caf.array(string.split(/((?:\\\\)+)/), (str, i) =>
Caf.mod(i, 2) === 0 ? str.replace(/\\ /g, " ") : str
).join("");
},
escapeNewLines: function(string) {
Expand All @@ -28,10 +27,8 @@ Caf.defMod(module, () => {
split = charsToEscape.match(/\\/)
? [string]
: string.split(/((?:\\.)+)/);
return Caf.array(
split,
(str, i) =>
Caf.mod(i, 2) === 0 ? str.replace(charsRegExp, "\\$1") : str
return Caf.array(split, (str, i) =>
Caf.mod(i, 2) === 0 ? str.replace(charsRegExp, "\\$1") : str
).join("");
},
legalUnquotedPropName: (legalUnquotedPropName = /^(0|[1-9][0-9]*|[a-z_][0-9_a-z]*)$/i),
Expand Down
16 changes: 7 additions & 9 deletions source/CaffeineScript/OperatorHelper.js
Expand Up @@ -223,15 +223,13 @@ Caf.defMod(module, () => {
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
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
Expand Down
2 changes: 1 addition & 1 deletion source/CaffeineScript/Rules/ControlStructures.js
Expand Up @@ -51,7 +51,7 @@ Caf.defMod(module, () => {
"controlStructorClauseJoiner thenDo _? body:lineOfStatementsOrBlock",
elseClause:
"controlStructorClauseJoiner else _? lineOfStatementsOrBlock",
controlStructorClauseJoiner: ["_", "end"],
controlStructorClauseJoiner: "_? end?",
catch: /catch\b/,
try: /try\b/,
ifUnlessWhileUntil: /(if|unless|while|until)\b/,
Expand Down
5 changes: 2 additions & 3 deletions source/CaffeineScript/Rules/ObjectLiterals.js
Expand Up @@ -50,9 +50,8 @@ Caf.defMod(module, () => {
{
getStn: function() {
let children;
children = Caf.array(
this.getMatchStns(),
m => (m instanceof ObjectStn.class ? m.children : m)
children = Caf.array(this.getMatchStns(), m =>
m instanceof ObjectStn.class ? m.children : m
);
return ObjectStn(children);
}
Expand Down
2 changes: 1 addition & 1 deletion source/CaffeineScript/Rules/Statements.js
Expand Up @@ -56,7 +56,7 @@ Caf.defMod(module, () => {
importBody: ["root", { stnFactory: "ImportBodyStn" }],
newLineStatementExtension: [
"end lineStartBinaryOperatorAndExpression",
"end &/\\??\\./ valueExtension+ binaryOperatorSequenceExtension?"
"end &/\\??\\.(?!\\d)/ valueExtension+ binaryOperatorSequenceExtension?"
],
lineOfStatements: {
pattern: [
Expand Down
20 changes: 9 additions & 11 deletions source/CaffeineScript/SemanticTree/BaseStn.js
Expand Up @@ -181,17 +181,15 @@ Caf.defMod(module, () => {
stnTypeStopPattern,
_foundList = []
) {
Caf.each2(
this.children,
child =>
stnTypePattern.test(child.type)
? _foundList.push(child)
: !(
Caf.exists(stnTypeStopPattern) &&
stnTypeStopPattern.test(child.type)
)
? child.find(stnTypePattern, stnTypeStopPattern, _foundList)
: undefined
Caf.each2(this.children, child =>
stnTypePattern.test(child.type)
? _foundList.push(child)
: !(
Caf.exists(stnTypeStopPattern) &&
stnTypeStopPattern.test(child.type)
)
? child.find(stnTypePattern, stnTypeStopPattern, _foundList)
: undefined
);
return _foundList.length === 0 ? null : _foundList;
};
Expand Down
8 changes: 4 additions & 4 deletions source/CaffeineScript/SemanticTree/ScopeStnMixin.js
Expand Up @@ -257,10 +257,10 @@ Caf.defMod(module, () => {
initializer
)}`
: initializer.toJsExpression != null
? `${Caf.toString(identifier)} = ${Caf.toString(
initializer.toJsExpression()
)}`
: identifier,
? `${Caf.toString(identifier)} = ${Caf.toString(
initializer.toJsExpression()
)}`
: identifier,
(initializer, identifier) =>
!identifiersAssignedInParentScopes ||
!identifiersAssignedInParentScopes[identifier]
Expand Down
Expand Up @@ -124,8 +124,8 @@ Caf.defMod(module, () => {
operatorPrecidence === parentOperatorPrecidence &&
isLeftOperand ===
getPrecidenceLevelIsLeftAssociative(operatorPrecidence)
? false
: true);
? false
: true);
};
}
));
Expand Down
108 changes: 52 additions & 56 deletions source/CaffeineScript/SemanticTree/StnsGeneratingJs/ClassStn.js
Expand Up @@ -101,63 +101,59 @@ Caf.defMod(module, () => {
)
),
StatementsStn(
(statementsToCount = Caf.array(
body.children,
stn =>
stn.type === "Object"
? Caf.array(stn.children, objectPropValueStn => {
let propNameStn,
propValueStn,
assignToStn,
propName,
isThisProp;
[
propNameStn,
propValueStn
] = objectPropValueStn.children;
assignToStn = (() => {
switch (propNameStn.type) {
case "ObjectPropName":
({ propName, isThisProp } = propNameStn);
return isThisProp
? ThisStn(
IdentifierStn({ identifier: propName })
)
: propName === "constructor"
? ((constructorStn = propValueStn), null)
: AccessorStn(
ThisStn(
IdentifierStn({
identifier: "prototype"
})
),
IdentifierStn({
identifier: propName
})
);
case "ObjectLiteralAccessor":
return AccessorStn(
ThisStn(
IdentifierStn({ identifier: "prototype" })
),
propNameStn.children
);
default:
return (() => {
throw new Error(
`unknown object property name Stn type: ${Caf.toString(
propNameStn.type
)}`
(statementsToCount = Caf.array(body.children, stn =>
stn.type === "Object"
? Caf.array(stn.children, objectPropValueStn => {
let propNameStn,
propValueStn,
assignToStn,
propName,
isThisProp;
[
propNameStn,
propValueStn
] = objectPropValueStn.children;
assignToStn = (() => {
switch (propNameStn.type) {
case "ObjectPropName":
({ propName, isThisProp } = propNameStn);
return isThisProp
? ThisStn(
IdentifierStn({ identifier: propName })
)
: propName === "constructor"
? ((constructorStn = propValueStn), null)
: AccessorStn(
ThisStn(
IdentifierStn({
identifier: "prototype"
})
),
IdentifierStn({ identifier: propName })
);
})();
}
})();
return (
assignToStn &&
AssignmentStn(assignToStn, propValueStn)
);
})
: stn
case "ObjectLiteralAccessor":
return AccessorStn(
ThisStn(
IdentifierStn({ identifier: "prototype" })
),
propNameStn.children
);
default:
return (() => {
throw new Error(
`unknown object property name Stn type: ${Caf.toString(
propNameStn.type
)}`
);
})();
}
})();
return (
assignToStn &&
AssignmentStn(assignToStn, propValueStn)
);
})
: stn
))
)
);
Expand Down
Expand Up @@ -166,8 +166,8 @@ Caf.defMod(module, () => {
statementStns
])
: preBodyStatements
? [preBodyStatements, statementStns]
: statementStns
? [preBodyStatements, statementStns]
: statementStns
);
};
this.getter({
Expand Down
16 changes: 8 additions & 8 deletions source/CaffeineScript/SemanticTree/StnsGeneratingJs/RegExpStn.js
Expand Up @@ -30,14 +30,14 @@ Caf.defMod(module, () => {
return !childrenNodes || childrenNodes.length === 0
? this.createSourceNode("/(?:)/")
: hasInterpolation
? this.createSourceNode(
"RegExp(`",
childrenNodes,
"`",
modifiers ? [", '", modifiers, "'"] : undefined,
")"
)
: this.createSourceNode("/", childrenNodes, "/", modifiers);
? this.createSourceNode(
"RegExp(`",
childrenNodes,
"`",
modifiers ? [", '", modifiers, "'"] : undefined,
")"
)
: this.createSourceNode("/", childrenNodes, "/", modifiers);
};
}
));
Expand Down
52 changes: 26 additions & 26 deletions source/CaffeineScript/SemanticTree/StnsGeneratingJs/RootStn.js
Expand Up @@ -38,32 +38,32 @@ Caf.defMod(module, () => {
this.statementsSourceNodes
)
: options.module
? ((identifiersToImport = Caf.array(
this.generateImportMap(),
(v, k) => `${Caf.toString(k)} = global.${Caf.toString(k)}`
)),
(statementsSourceNode = this.statements.toSourceNode({
returnAction: true
})),
(lets = compactFlatten([
identifiersToImport,
this.requiredIdentifierLets
])),
this.createSourceNode(
"\"use strict\"\nlet Caf = require('caffeine-script-runtime');\nCaf.defMod(module, () => {",
lets.length > 0
? `let ${Caf.toString(lets.join(", "))}; `
: undefined,
statementsSourceNode,
"});"
))
: (({ statementsSourceNodes } = this),
this.createSourceNode(
present((autoLets = this.getAutoLets()))
? [autoLets, "; "]
: undefined,
statementsSourceNodes
));
? ((identifiersToImport = Caf.array(
this.generateImportMap(),
(v, k) => `${Caf.toString(k)} = global.${Caf.toString(k)}`
)),
(statementsSourceNode = this.statements.toSourceNode({
returnAction: true
})),
(lets = compactFlatten([
identifiersToImport,
this.requiredIdentifierLets
])),
this.createSourceNode(
"\"use strict\"\nlet Caf = require('caffeine-script-runtime');\nCaf.defMod(module, () => {",
lets.length > 0
? `let ${Caf.toString(lets.join(", "))}; `
: undefined,
statementsSourceNode,
"});"
))
: (({ statementsSourceNodes } = this),
this.createSourceNode(
present((autoLets = this.getAutoLets()))
? [autoLets, "; "]
: undefined,
statementsSourceNodes
));
};
this.prototype.rootUpdateScope = function() {
return !this._scopeHasBeenUpdated
Expand Down
Expand Up @@ -98,15 +98,15 @@ Caf.defMod(module, () => {
})(),
c.toSourceNode({ generateReturnStatement: true }))
: generateStatements
? c.toSourceNode({
statement: !classBody,
generateStatements: true,
parentIsStatements: true
})
: c.toSourceNode({
expression: true,
returnValueIsIgnored: i < lines.length - 1
});
? c.toSourceNode({
statement: !classBody,
generateStatements: true,
parentIsStatements: true
})
: c.toSourceNode({
expression: true,
returnValueIsIgnored: i < lines.length - 1
});
return a;
},
null,
Expand Down

0 comments on commit 1a2da83

Please sign in to comment.