Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 4 additions & 112 deletions crates/angular_conformance/snapshots/angular.snap.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
| ast_serializer | 6 | 0 | 0 | 0 | 6 | 100.0% |
| ast_spans | 55 | 0 | 0 | 0 | 55 | 100.0% |
| expression_lexer | 154 | 0 | 0 | 0 | 154 | 100.0% |
| expression_parser | 401 | 1 | 1 | 0 | 403 | 99.5% |
| expression_parser | 402 | 0 | 1 | 0 | 403 | 99.8% |
| expression_serializer | 44 | 0 | 0 | 0 | 44 | 100.0% |
| html_lexer | 291 | 6 | 0 | 0 | 297 | 98.0% |
| html_parser | 89 | 1 | 0 | 0 | 90 | 98.9% |
| html_lexer | 297 | 0 | 0 | 0 | 297 | 100.0% |
| html_parser | 90 | 0 | 0 | 0 | 90 | 100.0% |
| html_whitespace | 21 | 0 | 0 | 0 | 21 | 100.0% |
| r3_transform | 180 | 4 | 0 | 0 | 184 | 97.8% |
| shadow_css | 185 | 2 | 0 | 0 | 187 | 98.9% |
| style_parser | 15 | 0 | 0 | 0 | 15 | 100.0% |
| **Total** | **1441** | **14** | **1** | **0** | **1456** | **99.0%** |
| **Total** | **1449** | **6** | **1** | **0** | **1456** | **99.5%** |

## Failed Tests

Expand All @@ -29,114 +29,6 @@ Path: `parser/parseAction/template literals/should report error if interpolation
Unexpected parse errors: ["Unexpected token } at column 10 in [`hello ${}`]", "Template literal interpolation cannot be empty at column 10 in [`hello ${}`]"]
```

#### should report an error if a template literal with an interpolation is not closed: ExpectBindingError { input: "`hello ${a}", error_contains: "Unterminated template literal" }
Path: `parser/parseAction/template literals/should report an error if a template literal with an interpolation is not closed`

**Expected:**
```
Error containing: Unterminated template literal
```

**Actual:**
```
No errors
```

### html_lexer

#### should parse a processing instruction: HtmlLexerTest { input: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>", test_type: HumanizeParts, expected: [Array [String("TokenType.PROCESSING_INSTRUCTION"), String("xml version=\"1.0\" encoding=\"UTF-8\"")], Array [String("TokenType.EOF")]], options: None }
Path: `HtmlLexer/processing instructions/should parse a processing instruction`

**Expected:**
```
Token 0: Array [String("TokenType.PROCESSING_INSTRUCTION"), String("xml version=\"1.0\" encoding=\"UTF-8\"")]
```

**Actual:**
```
Token 0: Array [String("TokenType.TEXT"), String("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")]
```

#### should parse a processing instruction ending with > instead of ?>: HtmlLexerTest { input: "<?xml version=\"1.0\" encoding=\"UTF-8\">", test_type: HumanizeParts, expected: [Array [String("TokenType.PROCESSING_INSTRUCTION"), String("xml version=\"1.0\" encoding=\"UTF-8\"")], Array [String("TokenType.EOF")]], options: None }
Path: `HtmlLexer/processing instructions/should parse a processing instruction ending with > instead of ?>`

**Expected:**
```
Token 0: Array [String("TokenType.PROCESSING_INSTRUCTION"), String("xml version=\"1.0\" encoding=\"UTF-8\"")]
```

**Actual:**
```
Token 0: Array [String("TokenType.TEXT"), String("<?xml version=\"1.0\" encoding=\"UTF-8\">")]
```

#### should parse a processing instruction surrounded by other content: HtmlLexerTest { input: "<!DOCTYPE html>\n<?xml version=\"1.0\" encoding=\"UTF-8\"?> hello", test_type: HumanizeParts, expected: [Array [String("TokenType.DOC_TYPE"), String("DOCTYPE html")], Array [String("TokenType.TEXT"), String("\n")], Array [String("TokenType.PROCESSING_INSTRUCTION"), String("xml version=\"1.0\" encoding=\"UTF-8\"")], Array [String("TokenType.TEXT"), String(" hello")], Array [String("TokenType.EOF")]], options: None }
Path: `HtmlLexer/processing instructions/should parse a processing instruction surrounded by other content`

**Expected:**
```
5 tokens
```

**Actual:**
```
3 tokens: [Array [String("TokenType.DOC_TYPE"), String("DOCTYPE html")], Array [String("TokenType.TEXT"), String("\n<?xml version=\"1.0\" encoding=\"UTF-8\"?> hello")], Array [String("TokenType.EOF")]]
```

#### should parse a processing instruction that contains question marks inside quoted content: HtmlLexerTest { input: "<?xml version=\"?\" encoding=\"UTF?>-8\"?>", test_type: HumanizeParts, expected: [Array [String("TokenType.PROCESSING_INSTRUCTION"), String("xml version=\"?\" encoding=\"UTF?>-8\"")], Array [String("TokenType.EOF")]], options: None }
Path: `HtmlLexer/processing instructions/should parse a processing instruction that contains question marks inside quoted content`

**Expected:**
```
Token 0: Array [String("TokenType.PROCESSING_INSTRUCTION"), String("xml version=\"?\" encoding=\"UTF?>-8\"")]
```

**Actual:**
```
Token 0: Array [String("TokenType.TEXT"), String("<?xml version=\"?\" encoding=\"UTF?>-8\"?>")]
```

#### should store the location of a processing instruction: HtmlLexerTest { input: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>", test_type: HumanizeSourceSpans, expected: [Array [String("TokenType.PROCESSING_INSTRUCTION"), String("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")], Array [String("TokenType.EOF"), String("")]], options: None }
Path: `HtmlLexer/processing instructions/should store the location of a processing instruction`

**Expected:**
```
Token 0: Array [String("TokenType.PROCESSING_INSTRUCTION"), String("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")]
```

**Actual:**
```
Token 0: Array [String("TokenType.TEXT"), String("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")]
```

#### should report missing end of a processing instruction: HtmlLexerTest { input: "<?", test_type: HumanizeErrors, expected: [Array [String("Unexpected character \"EOF\""), String("0:2")]], options: None }
Path: `HtmlLexer/processing instructions/should report missing end of a processing instruction`

**Expected:**
```
1 errors
```

**Actual:**
```
0 errors
```

### html_parser

#### should ignore processing instruction: HumanizeDom { input: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>hello", expected: [Array [String("html.Text"), String("hello"), Number(0.0), Array [String("hello")]]] }
Path: `HtmlParser/parse/ignored syntax/should ignore processing instruction`

**Expected:**
```
[Array [String("html.Text"), String("hello"), Number(0.0), Array [String("hello")]]]
```

**Actual:**
```
[Array [String("html.Text"), String("<?xml version=\"1.0\" encoding=\"UTF-8\"?>hello"), Number(0), Array [String("<?xml version=\"1.0\" encoding=\"UTF-8\"?>hello")]]]
```

### r3_transform

#### should ignore <script> elements inherited into custom namespaces: ExpectFromHtml { input: "<xhtml:div xmlns:xhtml=\"http://www.w3.org/1999/xhtml\"><script [textContent]=\"evil\"></script><span>safe</span></xhtml:div>", expected: [Array [String("Element"), String(":xhtml:div")], Array [String("TextAttribute"), String(":xmlns:xhtml"), String("http://www.w3.org/1999/xhtml")], Array [String("Element"), String(":xhtml:span")], Array [String("Text"), String("safe")]], ignore_error: false }
Expand Down
1 change: 1 addition & 0 deletions crates/angular_conformance/src/subsystems/html_lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ impl HtmlLexerRunner {
HtmlTokenType::AttrValueText => "ATTR_VALUE_TEXT",
HtmlTokenType::AttrValueInterpolation => "ATTR_VALUE_INTERPOLATION",
HtmlTokenType::DocType => "DOC_TYPE",
HtmlTokenType::ProcessingInstruction => "PROCESSING_INSTRUCTION",
HtmlTokenType::ExpansionFormStart => "EXPANSION_FORM_START",
HtmlTokenType::ExpansionCaseValue => "EXPANSION_CASE_VALUE",
HtmlTokenType::ExpansionCaseExpStart => "EXPANSION_CASE_EXP_START",
Expand Down
70 changes: 70 additions & 0 deletions crates/oxc_angular_compiler/src/ast/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,76 @@ pub enum AngularExpression<'a> {
}

impl<'a> AngularExpression<'a> {
/// Whether this tree is more than `limit` nodes deep (a lone node is 1 deep).
///
/// Walks the tree with an explicit stack, so a deep tree cannot overflow the
/// call stack here.
pub fn depth_exceeds(&self, limit: usize) -> bool {
let mut stack: std::vec::Vec<(&Self, usize)> = vec![(self, 1)];
while let Some((expr, depth)) = stack.pop() {
if depth > limit {
return true;
}
let mut push = |child| stack.push((child, depth + 1));
match expr {
Self::Empty(_)
| Self::ImplicitReceiver(_)
| Self::ThisReceiver(_)
| Self::LiteralPrimitive(_)
| Self::RegularExpressionLiteral(_) => {}
Self::Chain(e) => e.expressions.iter().for_each(push),
Self::Conditional(e) => {
push(&e.condition);
push(&e.true_exp);
push(&e.false_exp);
}
Self::PropertyRead(e) => push(&e.receiver),
Self::SafePropertyRead(e) => push(&e.receiver),
Self::KeyedRead(e) => {
push(&e.receiver);
push(&e.key);
}
Self::SafeKeyedRead(e) => {
push(&e.receiver);
push(&e.key);
}
Self::BindingPipe(e) => {
push(&e.exp);
e.args.iter().for_each(push);
}
Self::LiteralArray(e) => e.expressions.iter().for_each(push),
Self::LiteralMap(e) => e.values.iter().for_each(push),
Self::Interpolation(e) => e.expressions.iter().for_each(push),
Self::Binary(e) => {
push(&e.left);
push(&e.right);
}
Self::Unary(e) => push(&e.expr),
Self::PrefixNot(e) => push(&e.expression),
Self::TypeofExpression(e) => push(&e.expression),
Self::VoidExpression(e) => push(&e.expression),
Self::NonNullAssert(e) => push(&e.expression),
Self::Call(e) => {
push(&e.receiver);
e.args.iter().for_each(push);
}
Self::SafeCall(e) => {
push(&e.receiver);
e.args.iter().for_each(push);
}
Self::TaggedTemplateLiteral(e) => {
push(&e.tag);
e.template.expressions.iter().for_each(push);
}
Self::TemplateLiteral(e) => e.expressions.iter().for_each(push),
Self::ParenthesizedExpression(e) => push(&e.expression),
Self::SpreadElement(e) => push(&e.expression),
Self::ArrowFunction(e) => push(&e.body),
}
}
false
}

/// Returns the span of this expression.
pub fn span(&self) -> ParseSpan {
match self {
Expand Down
2 changes: 2 additions & 0 deletions crates/oxc_angular_compiler/src/ast/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ pub enum BlockType {
Boundary,
/// An @error block (inside @defer or @boundary).
Error,
/// A block with any other name (`@ifx`), which Angular reports as unrecognized.
Unknown,
}

/// A block node (@if, @for, @switch, @defer).
Expand Down
17 changes: 17 additions & 0 deletions crates/oxc_angular_compiler/src/component/decorator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,23 @@ pub fn extract_component_metadata<'a>(
_ => None,
}
.map(|span| Span::new(span.start + 1, span.end - 1));
// ngtsc parses an inline literal's raw text, escapes and all,
// with Angular's `EscapedCharacterCursor`: the text it reads
// can differ from the literal's value (`\400`, a line
// continuation), and a lone surrogate has no `&str` value.
if let (Some(span), Some(source)) = (metadata.template_span, source_text)
&& let Some(raw) = source.get(span.start as usize..span.end as usize)
&& raw.contains('\\')
{
let is_template_literal =
matches!(&prop.value, Expression::TemplateLiteral(_));
if let Some((text, _)) =
super::source_locations::cook_literal(raw, 0, is_template_literal)
&& metadata.template.as_ref().is_none_or(|value| value.as_str() != text)
{
metadata.template = Some(Ident::from(allocator.alloc_str(&text)));
}
}
}
"templateUrl" => {
// Evaluated like ngtsc's `parseTemplateDeclaration`, so a
Expand Down
Loading
Loading