-
Notifications
You must be signed in to change notification settings - Fork 192
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
Implement {{#-in-element
API.
#331
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ import { ValueReference } from '../../compiled/expressions/value'; | |
import { CompiledArgs, EvaluatedArgs } from '../../compiled/expressions/args'; | ||
import { AttributeManager } from '../../dom/attribute-managers'; | ||
import { ElementOperations } from '../../builder'; | ||
import { Assert } from './vm'; | ||
|
||
export class TextOpcode extends Opcode { | ||
public type = "text"; | ||
|
@@ -62,6 +63,38 @@ export class OpenPrimitiveElementOpcode extends Opcode { | |
} | ||
} | ||
|
||
export class PushRemoteElementOpcode extends Opcode { | ||
public type = "push-remote-element"; | ||
|
||
evaluate(vm: VM) { | ||
let reference = vm.frame.getOperand<Simple.Element>(); | ||
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. For future readers: this is unsafe but we decided to punt on error-ing since this is still experimental 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. Should probably remove those comments tho :P |
||
let cache = isConstReference(reference) ? undefined : new ReferenceCache(reference); | ||
let element = cache ? cache.peek() : reference.value(); | ||
|
||
vm.stack().pushRemoteElement(element); | ||
|
||
if (cache) { | ||
vm.updateWith(new Assert(cache)); | ||
} | ||
} | ||
|
||
toJSON(): OpcodeJSON { | ||
return { | ||
guid: this._guid, | ||
type: this.type, | ||
args: ['$OPERAND'] | ||
}; | ||
} | ||
} | ||
|
||
export class PopRemoteElementOpcode extends Opcode { | ||
public type = "pop-remote-element"; | ||
|
||
evaluate(vm: VM) { | ||
vm.stack().popRemoteElement(); | ||
} | ||
} | ||
|
||
export class OpenComponentElementOpcode extends Opcode { | ||
public type = "open-component-element"; | ||
|
||
|
@@ -345,6 +378,20 @@ export class CloseElementOpcode extends Opcode { | |
} | ||
} | ||
|
||
export class PopElementOpcode extends Opcode { | ||
public type = "pop-element"; | ||
|
||
evaluate(vm: VM) { | ||
vm.stack().popElement(); | ||
} | ||
} | ||
|
||
export interface StaticAttrOptions { | ||
namespace: string; | ||
name: string; | ||
value: string; | ||
} | ||
|
||
export class StaticAttrOpcode extends Opcode { | ||
public type = "static-attr"; | ||
|
||
|
34 changes: 34 additions & 0 deletions
34
packages/glimmer-runtime/lib/syntax/builtins/in-element.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { | ||
Statement as StatementSyntax | ||
} from '../../syntax'; | ||
|
||
import OpcodeBuilderDSL from '../../compiled/opcodes/builder'; | ||
import * as Syntax from '../core'; | ||
import Environment from '../../environment'; | ||
|
||
export default class InElementSyntax extends StatementSyntax { | ||
type = "in-element-statement"; | ||
|
||
public args: Syntax.Args; | ||
public templates: Syntax.Templates; | ||
public isStatic = false; | ||
|
||
constructor({ args, templates }: { args: Syntax.Args, templates: Syntax.Templates }) { | ||
super(); | ||
this.args = args; | ||
this.templates = templates; | ||
} | ||
|
||
compile(dsl: OpcodeBuilderDSL, env: Environment) { | ||
let { args, templates } = this; | ||
|
||
dsl.block({ templates, args }, (dsl, BEGIN, END) => { | ||
dsl.putArgs(args); | ||
dsl.test('simple'); | ||
dsl.jumpUnless(END); | ||
dsl.pushRemoteElement(); | ||
dsl.evaluate('default'); | ||
dsl.popRemoteElement(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
we can make this configurable for bonus points, which would allow inserting into the middle of an element 😉
but we can do it as a follow-up.