Skip to content
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

add block param nodes #1552

Merged
merged 3 commits into from
Jan 26, 2024
Merged

add block param nodes #1552

merged 3 commits into from
Jan 26, 2024

Conversation

patricklx
Copy link
Contributor

@patricklx patricklx commented Jan 25, 2024

part of #1490

made it backwards compatible

bin/run-tests.mjs Outdated Show resolved Hide resolved
let [Foo] = ast.body;
if (assertNodeType(Foo, 'BlockStatement')) {
let [ab, cd, efg] = guardArray({ blockParamNodes: Foo.program.blockParamNodes }, { min: 3 });
locEqual(ab, 1, 11, 1, 13);
Copy link
Contributor

Choose a reason for hiding this comment

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

can the value / name be asserted as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i think this should be done separately. i will add it in parser-node-test

Copy link
Contributor

@NullVoxPopuli NullVoxPopuli left a comment

Choose a reason for hiding this comment

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

revert bin/run-tests.mjs <3

@@ -293,6 +295,16 @@ export interface HashPair extends BaseNode {
value: Expression;
}

/**
* a param inside the pipes of elements or mustache blocks,
Copy link
Contributor

Choose a reason for hiding this comment

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

🙌 perfect! thank you!

let [Foo] = ast.body;
if (assertNodeType(Foo, 'ElementNode')) {
let [ab, cd, efg] = guardArray({ blockParamNodes: Foo.blockParamNodes }, { min: 3 });
locEqual(ab, 1, 8, 1, 12);
Copy link
Contributor

Choose a reason for hiding this comment

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

since the signature for locEqual is

function locEqual(
  node: AST.Node | null | undefined,
  startLine: number,
  startColumn: number,
  endLine: number,
  endColumn: number,
  message = JSON.stringify(node)
) {

should endColumn be 2 characters more than startColumn? right now it sees like.. 4?

 locEqual(ab, 1, 8, 1, 12); // 12 - 8 = 4, but the node is 'ab', 2
 locEqual(cd, 1, 12, 1, 15); // 15 - 12 = 3, but the node is 'cd', 2
 locEqual(efg, 1, 15, 1, 19); // 19 - 15 = 4, but the node is 'efg', 3

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh! thanks for noticing. since those are initially parsed as attributes by hbs parser the location contains the pipe as well... need to fix it. not sure why it also contains the whitespace, might be a bug in hbs parser

't=<Foo as |ab cd efg|></Foo>'
t.slice(8,12)
'|ab '
t.slice(12,15)
'cd '
t.slice(15,19)
'efg|'

Copy link
Contributor

@NullVoxPopuli NullVoxPopuli left a comment

Choose a reason for hiding this comment

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

ranges look good, thank you!

@NullVoxPopuli NullVoxPopuli merged commit c7f954b into glimmerjs:main Jan 26, 2024
6 checks passed
chancancode added a commit that referenced this pull request Feb 25, 2024
This reverts commit c7f954b, reversing
changes made to e934005.
chancancode added a commit that referenced this pull request Feb 25, 2024
The original commit has a few issues:

- Type safety
- Added a new AST node, which is unnecessary since we already have
  `VarHead`, but is also a breaking change and is kind of breakage
  we have been careful to avoid in this area thus far
- The parsing is robust against a few classes of edge cases

This rework the same feature (on the `Block`/`BlockStatement` side)
and adds more test coverage for the feature. Also reanmed the field
to `block.params`.
chancancode added a commit that referenced this pull request Feb 25, 2024
The original commit has a few issues:

- Type safety
- Added a new AST node, which is unnecessary since we already have
  `VarHead`, but is also a breaking change and is kind of breakage
  we have been careful to avoid in this area thus far
- The parsing is robust against a few classes of edge cases

This rework the same feature (on the `Block`/`BlockStatement` side)
and adds more test coverage for the feature. Also reanmed the field
to `block.params`.
chancancode added a commit that referenced this pull request Feb 25, 2024
The original commit has a few issues:

- Type safety
- Added a new AST node, which is unnecessary since we already have
  `VarHead`, but is also a breaking change and is kind of breakage
  we have been careful to avoid in this area thus far
- The parsing is robust against a few classes of edge cases

This rework the same feature (on the `Block`/`BlockStatement` side)
and adds more test coverage for the feature. Also reanmed the field
to `block.params`.
chancancode added a commit that referenced this pull request Feb 25, 2024
The original commit has a few issues:

- Type safety
- Added a new AST node, which is unnecessary since we already have
  `VarHead`, but is also a breaking change and is kind of breakage
  we have been careful to avoid in this area thus far
- The parsing is robust against a few classes of edge cases

This rework the same feature (on the `Block`/`BlockStatement` side)
and adds more test coverage for the feature. Also reanmed the field
to `block.params`.
chancancode added a commit that referenced this pull request Feb 26, 2024
This reverts commit c7f954b, reversing
changes made to e934005.
chancancode added a commit that referenced this pull request Feb 26, 2024
The original commit has a few issues:

- Type safety
- Added a new AST node, which is unnecessary since we already have
  `VarHead`, but is also a breaking change and is kind of breakage
  we have been careful to avoid in this area thus far
- The parsing is robust against a few classes of edge cases

This rework the same feature (on the `Block`/`BlockStatement` side)
and adds more test coverage for the feature. Also renamed the field
to `block.params`.
chancancode added a commit that referenced this pull request Feb 27, 2024
The previous/existing "parsing" code tries to piggy back on letting
the HTML tokenizer/parse parse out the block params syntax into
attribute nodes and tries to recover the information after the fact

This is fundamentally broken and suffers from some wild edge cases
like:

```
<div as="" |foo="bar|>...</div> // => <div as |foo|>...</div>
```

This is especially problematic in light of wanting to retain the
source spans of the block params nodes.

This commit rework the block params parsing and integrate it into
the normal parsing pass in the appropiate time.
chancancode added a commit that referenced this pull request Feb 27, 2024
The previous/existing "parsing" code tries to piggy back on letting
the HTML tokenizer/parser parse out the block params syntax into
attribute nodes and tries to recover the information after the fact

This is fundamentally broken and suffers from some wild edge cases
like:

```
<div as="" |foo="bar|>...</div> // => <div as |foo|>...</div>
```

This is especially problematic in light of wanting to retain the
source spans of the block params nodes.

This commit rework the block params parsing and integrate it into
the normal parsing pass in the appropiate time.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants