-
Notifications
You must be signed in to change notification settings - Fork 152
[WIP] Ember cli classic #185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
512a11f
463fe10
7c1c001
94a4a1c
ad83f78
85772e1
ae2ed0a
f669473
769aa6a
1b852a4
f6f0150
d77b7d1
9712b70
8362757
fe3be18
a78802e
58dc295
474862c
589f283
5566127
aa702ed
af52f92
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { helper } from "@ember/component/helper"; | ||
|
||
// For some reason Ember doesn't include the helper runtime from `@css-blocks/glimmer` | ||
// in the build and throws a "missing module" error at runtime. The contents have been | ||
// temporarily copied to `./tmp` as a workaround instead... this will block release. | ||
// import { classnames } from "@css-blocks/glimmer/dist/src/helpers/classnames"; | ||
import { classnames } from "./tmp"; | ||
|
||
export default helper(classnames); | ||
export { classnames }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { concat } from "@css-blocks/glimmer/dist/src/helpers/concat"; | ||
import { helper } from "@ember/component/helper"; | ||
|
||
export default helper(concat); | ||
export { concat }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
|
||
const e = (m) => { throw new Error(m); }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this module looks pretty complex, do we have associated unit tests? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copy pasta from the unit tested version in |
||
const toStr = (s) => typeof s === "symbol" ? s.toString() : "" + s; | ||
const num = (v) => typeof v[0] === "number" ? v.shift() : e("not a number: " + toStr(v[0])); | ||
const str = (s) => toStr(s.shift()); | ||
const truthyString = (v) => { | ||
let s = v.shift(); | ||
if (!s && s !== 0) | ||
return; | ||
return s.toString(); | ||
}; | ||
const bool = (v) => !!v.shift(); | ||
function classnames(stack) { | ||
stack = stack.slice(0); | ||
let sources = []; | ||
let classes = []; | ||
let nSources = num(stack); | ||
let nOutputs = num(stack); | ||
let canSetSource = true; | ||
let abort = () => canSetSource = false; | ||
let isSourceSet = (n) => sources[n]; | ||
let setSource = (n) => { if (canSetSource) | ||
sources[n] = true; }; | ||
while (nSources-- > 0) { | ||
sourceExpr(stack, isSourceSet, setSource, abort); | ||
canSetSource = true; | ||
} | ||
while (nOutputs-- > 0) { | ||
let c = str(stack); | ||
if (boolExpr(stack, isSourceSet)) | ||
classes.push(c); | ||
} | ||
return classes.join(" "); | ||
} | ||
|
||
function sourceExpr(stack, isSourceSet, setSource, abort) { | ||
let enforceSwitch = true; | ||
let type = num(stack); | ||
if (type & 1 /* dependency */) { | ||
let numDeps = num(stack); | ||
while (numDeps-- > 0) { | ||
let depIndex = num(stack); | ||
if (!isSourceSet(depIndex)) | ||
enforceSwitch = abort(); | ||
} | ||
} | ||
if (type & 2 /* boolean */) { | ||
if (!bool(stack)) | ||
abort(); | ||
} | ||
if (type & 4 /* switch */) { | ||
let nValues = num(stack); | ||
let ifFalsy = num(stack); | ||
let value = truthyString(stack); | ||
if (value === undefined) { | ||
switch (ifFalsy) { | ||
case 2 /* default */: | ||
value = str(stack); | ||
break; | ||
case 0 /* error */: | ||
if (enforceSwitch) | ||
e("string expected"); // TODO: error message | ||
break; | ||
case 1 /* unset */: | ||
abort(); | ||
break; | ||
default: | ||
e("wtf"); | ||
} | ||
} | ||
while (nValues-- > 0) { | ||
let matchValue = str(stack); | ||
let nSources = num(stack); | ||
while (nSources-- > 0) { | ||
value === matchValue ? setSource(num(stack)) : num(stack); | ||
} | ||
} | ||
} | ||
else if (type === 0 /* ternary */) { | ||
let condition = bool(stack); | ||
let nTrue = num(stack); | ||
while (nTrue-- > 0) { | ||
condition ? setSource(num(stack)) : num(stack); | ||
} | ||
let nFalse = num(stack); | ||
while (nFalse-- > 0) { | ||
condition ? num(stack) : setSource(num(stack)); | ||
} | ||
} | ||
else { | ||
let nSources = num(stack); | ||
while (nSources-- > 0) { | ||
setSource(num(stack)); | ||
} | ||
} | ||
} | ||
function boolExpr(stack, isSourceSet) { | ||
let result; | ||
let type = num(stack); | ||
switch (type) { | ||
case -1 /* not */: | ||
return !boolExpr(stack, isSourceSet); | ||
case -3 /* and */: | ||
let nAnds = num(stack); | ||
result = true; | ||
while (nAnds-- > 0) { | ||
let nextResult = boolExpr(stack, isSourceSet); | ||
result = result && nextResult; | ||
} | ||
return result; | ||
case -2 /* or */: | ||
let nOrs = num(stack); | ||
result = false; | ||
while (nOrs-- > 0) { | ||
let nextResult = boolExpr(stack, isSourceSet); | ||
result = result || nextResult; | ||
} | ||
return result; | ||
default: | ||
return isSourceSet(type); | ||
} | ||
} | ||
|
||
export { classnames }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default, classnames } from '@css-blocks/ember-cli/helpers/classnames'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default, concat } from '@css-blocks/ember-cli/helpers/concat'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let transition to sync FS functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this foreclose on the ability to run multiple Broccoli plugins concurrently in the future?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe so. We're already running multiple instances of this broccoli plugin (one for each addon, engine, or app). Broccoli (according to spenner) runs the build step synchronously already, so we don't actually gain any perf benefits from async functions and instead are just left with that extra throwaway promise being created for each file system call.
If Broccoli begins running certain build steps asynchronously, this may be a perf bottleneck, but we'll need to update synchronous fs calls across the entire ecosystem to un-block it.
From a CSS Blocks perspective, there is no difference in sync vs async.