Skip to content

feat(compiler): Introduce InterpolationConfig into component#9158

Closed
lacolaco wants to merge 1 commit intoangular:masterfrom
lacolaco:laco-component-interpolation-config
Closed

feat(compiler): Introduce InterpolationConfig into component#9158
lacolaco wants to merge 1 commit intoangular:masterfrom
lacolaco:laco-component-interpolation-config

Conversation

@lacolaco
Copy link
Copy Markdown
Contributor

@lacolaco lacolaco commented Jun 11, 2016

Please check if the PR fulfills these requirements

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

  • Feature

What is the current behavior? (You can also link to an open issue here)

Interpolation symbols are defined as const INTERPOLATION_REGEXP.
This is not friendly to collaboration with other templating engines. (e.g. Python jinja)

What is the new behavior?

ComponentMetadata has a new property, interpolation, which has start/end symbols for interpolation.

@Component({
  template: `
  {% someProp %}
  `,
  interpolation: ['{%', '%}']
})
class SomeComp {
  someProp;
}

Does this PR introduce a breaking change?

  • No

If this PR contains a breaking change, please describe the impact and migration path for existing applications: ...

Other information:
This is re-implementation from #8906

cc/ @vicb

@lacolaco
Copy link
Copy Markdown
Contributor Author

lacolaco commented Jun 11, 2016

I'm not sure whether that config works well on the offline compiler because I don't know how to test it...

@lacolaco
Copy link
Copy Markdown
Contributor Author

lacolaco commented Jun 11, 2016

  • apply to I18nHtmlParser

@lacolaco lacolaco force-pushed the laco-component-interpolation-config branch 3 times, most recently from 33a7c54 to ba2b1bc Compare June 12, 2016 05:52
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interpolation: ['{{', '}}'] ?

Copy link
Copy Markdown
Contributor Author

@lacolaco lacolaco Jun 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, here should be new InterpolationConfig('{{', '}}') .
I think array is not type-safe. TypeScript cannot restrict that array's length.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Static checking with Class/Interface vs Runtime checking with compMeta.interpolation.length == 2
Which makes more sense?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can not instantiate objects in decorators, otherwise they are not statically analyzable. The current version works fine because your object has the same interface as InterpolationConfig (TS uses structural type checking) but IMO is too verbose.

You can use an Array and check the length in the Component ctor

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I'll do that. 👍

@vicb
Copy link
Copy Markdown
Contributor

vicb commented Jun 13, 2016

Great work on this PR !

I think you miss html_lexer, please add a test and update the code. Thaanks.

@lacolaco lacolaco force-pushed the laco-component-interpolation-config branch 2 times, most recently from 5a2052f to 5930d00 Compare June 14, 2016 12:00
@lacolaco
Copy link
Copy Markdown
Contributor Author

lacolaco commented Jun 14, 2016

@vicb Thank you for reviewing!
I saw html_lexer and updated it, but I didn't know how to test whether {% a %} is captured as interpolation.

I wrote following tests at html_lexer_spec.ts

      it('should parse interpolation', () => {
        expect(tokenizeAndHumanizeParts('{{ a }}')).toEqual([
          [HtmlTokenType.TEXT, '{{ a }}'], [HtmlTokenType.EOF]
        ]);

        expect(tokenizeAndHumanizeParts('{% a %}', null, {startSymbol: '{%', endSymbol: '%}'}))
            .toEqual([[HtmlTokenType.TEXT, '{% a %}'], [HtmlTokenType.EOF]]);
      });

Either case, the result is HtmlTokenType.TEXT. I'm not sure whether it is meaningful tests.

In template_parser_spec, I could know that well via BoundTextAst

           expect(humanizeTplAst(parser.parse(component, '{%a%}', [], [], 'TestComp'))).toEqual([
             // unparser doesn't know interpolation config. check only AST type.
             [BoundTextAst, '{{ a }}']
           ]);

Can I check html_lexer as well as template_parser?

@vicb
Copy link
Copy Markdown
Contributor

vicb commented Jun 16, 2016

Sorry for the delay, I'll try to check your PR by EOW. Could you please rebase ? Thanks

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return type :void

@vicb
Copy link
Copy Markdown
Contributor

vicb commented Jun 16, 2016

I have added some comments.

Could you please add some integration test.

It would be have to have nested and sibling component with a different config (also length should be different, ie not 2 and start vs end).

Thanks !

@lacolaco lacolaco force-pushed the laco-component-interpolation-config branch from 5930d00 to a36ec80 Compare June 16, 2016 04:25
@vicb vicb mentioned this pull request Jun 18, 2016
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a list BLACKLIST_REGEXPS

@vicb
Copy link
Copy Markdown
Contributor

vicb commented Jun 18, 2016

A few comments but your work is very good and we can probably merge early next week. You can squash the current commits.

Thanks, a few people have tried to implement this but haven't completed - including myself :)

@lacolaco
Copy link
Copy Markdown
Contributor Author

@vicb Thanks a lot, Victor. I really appreciate your kind help!
The rest of the work is to upgrade ts-api-guardian version after it's released.
I'll squash my commits after that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I use for...of statement? (thinking about ts2dart)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IBR.forEach(pattern => ...)

@lacolaco
Copy link
Copy Markdown
Contributor Author

I thought we need to be careful about ts2dart transformation for const , RegExp or etc.
Isn't it necessary now?

@vicb
Copy link
Copy Markdown
Contributor

vicb commented Jun 19, 2016

Isn't it necessary now?

If the tests pass you're fine

@vicb
Copy link
Copy Markdown
Contributor

vicb commented Jun 20, 2016

Is the remaining issue linked to api guardian not being updated ?

Please squash your commits.

Thanks again for your great work.

@lacolaco lacolaco force-pushed the laco-component-interpolation-config branch from 3565e8a to 892f44f Compare June 20, 2016 01:45
@lacolaco
Copy link
Copy Markdown
Contributor Author

@vicb I think so. Thanks.

@lacolaco
Copy link
Copy Markdown
Contributor Author

I've squashed commits in 892f44f

vicb pushed a commit to vicb/angular that referenced this pull request Jun 20, 2016
@vicb vicb closed this in #9367 Jun 20, 2016
vicb added a commit that referenced this pull request Jun 20, 2016
@lacolaco lacolaco deleted the laco-component-interpolation-config branch June 21, 2016 00:16
@angular-automatic-lock-bot
Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews cla: yes feature Label used to distinguish feature request from other issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants