Skip to content

Simpler codegen#673

Merged
Rich-Harris merged 12 commits intomasterfrom
codegen
Jun 26, 2017
Merged

Simpler codegen#673
Rich-Harris merged 12 commits intomasterfrom
codegen

Conversation

@Rich-Harris
Copy link
Copy Markdown
Member

This stops well short of the idea described in #652 (which I started investigating, but concluded it would probably add more complexity and indirection than it removes), but I think it goes a long way towards making the code-that-generates-the-code more readable.

// before
this.builders.unmount.addLine(
  `${this.generator.helper('detachNode')}( ${name} );`
);

// after
this.builders.unmount.addLine(
  `@detachNode( ${name} );`
);

Essentially @foo means 'alias foo, and register it as a helper if there's a helper called foo'. Similarly, for block-level aliases, as opposed to component-level, we can use #foo.

@Conduitry
Copy link
Copy Markdown
Member

Conduitry commented Jun 25, 2017

It looks like this has problems if the original component has things in it that look like these special identifiers. Compiling just the string @foo results in text = createText( "\\foo" );

Compiling {{'@foo'}} results in text = createText( text_value = '@foo' ); which seems fine.

Compiling #foo results in text = createText( "\#foo" ); which isn't ideal but technically works.

@Rich-Harris
Copy link
Copy Markdown
Member Author

Good catch! Should be fixed now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants