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
26 changes: 19 additions & 7 deletions crates/oxc_angular_compiler/src/class_metadata/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use oxc_ast::ast::{
Class, ClassElement, Decorator, Expression, FormalParameter, MethodDefinitionKind,
ObjectPropertyKind, PropertyKey, TSType, TSTypeName,
};
use oxc_span::GetSpan;
use oxc_str::Ident;

use crate::component::{ImportMap, NamespaceRegistry, R3DependencyMetadata};
Expand All @@ -20,7 +21,7 @@ use crate::output::ast::{
LiteralMapExpr, LiteralValue, OutputExpression, ReadPropExpr, ReadVarExpr,
};
use crate::output::oxc_converter::{
convert_oxc_expression, convert_plain_properties, is_plain_property,
convert_oxc_expression, convert_plain_properties, is_plain_property, make_raw_source,
};

/// Build the decorators metadata array expression.
Expand Down Expand Up @@ -158,7 +159,14 @@ pub fn build_decorator_metadata_array<'a>(

if !args_emitted && let Expression::CallExpression(call) = &decorator.expression {
for (arg_idx, arg) in call.arguments.iter().enumerate() {
let expr = arg.to_expression();
// A `...args` spread isn't an `Expression`; its raw source
// (`...X`) emits the same spread upstream copies verbatim.
let Some(expr) = arg.as_expression() else {
if let Some(raw) = make_raw_source(allocator, source_text, arg.span()) {
args.push(raw);
}
continue;
};
let converted = convert_oxc_expression(allocator, expr, source_text);
if let Some(mut converted) = converted {
// Same template-literal drop as the transformed path, applied
Expand Down Expand Up @@ -752,9 +760,13 @@ fn build_signal_query_decorator<'a>(

// Predicate: the first positional argument (required), reused as-is. A query with
// no locator is invalid (ngc errors); skip synthesis rather than emit a malformed
// decorator.
let predicate =
convert_oxc_expression(allocator, call.arguments.first()?.to_expression(), source_text)?;
// decorator. A `...args` spread isn't an `Expression`; like the compiled
// query's `WrappedNodeExpr` fallback, only the raw source can stand in.
let first = call.arguments.first()?;
let predicate = match first.as_expression() {
Some(expr) => convert_oxc_expression(allocator, expr, source_text)?,
None => make_raw_source(allocator, source_text, first.span())?,
};
let mut args = AllocVec::new_in(&allocator);
args.push(predicate);

Expand All @@ -763,8 +775,8 @@ fn build_signal_query_decorator<'a>(
// which preserves any options expression, object literal or not.
let mut options = AllocVec::new_in(&allocator);
if let Some(second) = call.arguments.get(1)
&& let Some(source_options) =
convert_oxc_expression(allocator, second.to_expression(), source_text)
&& let Some(expr) = second.as_expression()
&& let Some(source_options) = convert_oxc_expression(allocator, expr, source_text)
{
options.push(LiteralMapEntry::spread(source_options));
}
Expand Down
14 changes: 14 additions & 0 deletions crates/oxc_angular_compiler/src/component/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2722,6 +2722,13 @@ fn transform_angular_file_jit(
// / `styleUrls`, matching the AOT metadata extraction path.
let string_consts = collect_string_consts(allocator, &parser_ret.program);

// ngtsc's source-file rules (validation/): initializer APIs used outside a
// class member initializer (UNSUPPORTED_INITIALIZER_API_USAGE).
result.diagnostics.extend(crate::validation::initializer_api_usage_errors(
&parser_ret.program,
&string_consts,
));

// Build an import map so `find_angular_decorator` can verify that a bare
// `@Service()` is actually Angular's, not a same-named decorator from
// another library.
Expand Down Expand Up @@ -3126,6 +3133,13 @@ pub fn transform_angular_file(
));
}

// ngtsc's source-file rules (validation/): initializer APIs used outside a
// class member initializer (UNSUPPORTED_INITIALIZER_API_USAGE).
result.diagnostics.extend(crate::validation::initializer_api_usage_errors(
&parser_ret.program,
&string_consts,
));

#[cfg(feature = "cross_file_elision")]
let mut import_map =
build_import_map(allocator, &parser_ret.program.body, options.resolved_imports.as_ref());
Expand Down
382 changes: 302 additions & 80 deletions crates/oxc_angular_compiler/src/directive/decorator.rs

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions crates/oxc_angular_compiler/src/directive/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ pub use compiler::{
};
pub(crate) use decorator::find_directive_decorator;
pub(crate) use decorator::{
INPUT_API, MODEL_API, OUTPUT_API, OUTPUT_FROM_OBSERVABLE_API, QUERY_APIS, initializer_api,
initializer_api_call,
INPUT_API, InitializerApi, MODEL_API, OUTPUT_API, OUTPUT_FROM_OBSERVABLE_API, QUERY_APIS,
initializer_api, initializer_api_call,
};
pub use decorator::{
StringConsts, collect_string_consts, decorator_io_errors, extract_directive_metadata,
Expand All @@ -50,9 +50,9 @@ pub use metadata::{
};
pub(crate) use property_decorators::{
angular_class_decorator, angular_member_decorator, angular_param_decorator,
extract_host_bindings_in, extract_host_listeners_in, is_angular_core_decorator,
parse_decorator_queries, try_parse_signal_input, try_parse_signal_model,
try_parse_signal_output, unwrap_initializer_api_expr,
decorator_written_name, extract_host_bindings_in, extract_host_listeners_in,
is_angular_core_decorator, parse_decorator_queries, try_parse_signal_input,
try_parse_signal_model, try_parse_signal_output, unwrap_initializer_api_expr,
};
pub use property_decorators::{
extract_class_queries, extract_content_queries, extract_host_bindings, extract_host_listeners,
Expand Down
Loading
Loading