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
21 changes: 16 additions & 5 deletions crates/oxc_angular_compiler/src/component/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1649,6 +1649,7 @@ pub fn transform_angular_file(
template,
&mut metadata,
path,
source,
options,
view_queries,
content_queries,
Expand Down Expand Up @@ -2315,6 +2316,7 @@ fn compile_component_full<'a>(
template: &'a str,
metadata: &mut ComponentMetadata<'a>,
file_path: &str,
source: &str,
options: &TransformOptions,
view_queries: OxcVec<'a, R3QueryMetadata<'a>>,
content_queries: OxcVec<'a, R3QueryMetadata<'a>>,
Expand Down Expand Up @@ -2589,13 +2591,22 @@ fn compile_component_full<'a>(
allocator,
));

// Build the debug info
// Note: line_number is 1-indexed. We don't have access to the actual source
// line number here, but Angular uses the class declaration position.
// For now we use line 1, but this could be enhanced if we pass line info.
// Compute the 1-indexed line number of the class declaration from its byte offset
let class_line_number = {
let offset = metadata.class_span.start as usize;
let mut line = 1u32;
for &byte in &source.as_bytes()[..offset.min(source.len())] {
if byte == b'\n' {
line += 1;
}
}
line
};

// Build the debug info with the actual class declaration line number
let debug_info = R3ClassDebugInfo::new(component_type, metadata.class_name.clone())
.with_file_path(Atom::from_in(file_path, allocator))
.with_line_number(1); // TODO: Get actual line number from class declaration
.with_line_number(class_line_number);

// Compile to IIFE-wrapped expression
let debug_info_expr = compile_class_debug_info(allocator, &debug_info);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
source: crates/oxc_angular_compiler/tests/integration_test.rs
expression: result.code
---

import { Component } from '@angular/core';
import * as i0 from '@angular/core';

Expand All @@ -21,5 +22,5 @@ static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({type:StyledComponent,select
}
(() =>{
(((typeof ngDevMode === "undefined") || ngDevMode) && i0setClassDebugInfo(StyledComponent,
{className:"StyledComponent",filePath:"styled.component.ts",lineNumber:1}));
{className:"StyledComponent",filePath:"styled.component.ts",lineNumber:9}));
})();
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
source: crates/oxc_angular_compiler/tests/integration_test.rs
expression: result.code
---

import { Component } from '@angular/core';
import * as i0 from '@angular/core';

Expand All @@ -20,5 +21,5 @@ static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({type:MultiStyledComponent,s
}
(() =>{
(((typeof ngDevMode === "undefined") || ngDevMode) && i0.ɵsetClassDebugInfo(MultiStyledComponent,
{className:"MultiStyledComponent",filePath:"multi-styled.component.ts",lineNumber:1}));
{className:"MultiStyledComponent",filePath:"multi-styled.component.ts",lineNumber:12}));
})();
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
source: crates/oxc_angular_compiler/tests/integration_test.rs
expression: result.code
---

import { Component } from '@angular/core';
import * as i0 from '@angular/core';

Expand All @@ -20,5 +21,5 @@ static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({type:NoStylesComponent,sele
}
(() =>{
(((typeof ngDevMode === "undefined") || ngDevMode) && i0.ɵsetClassDebugInfo(NoStylesComponent,
{className:"NoStylesComponent",filePath:"no-styles.component.ts",lineNumber:1}));
{className:"NoStylesComponent",filePath:"no-styles.component.ts",lineNumber:8}));
})();
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
source: crates/oxc_angular_compiler/tests/integration_test.rs
expression: result.code
---

import { Component } from '@angular/core';
import * as i0 from '@angular/core';

Expand All @@ -28,5 +29,5 @@ static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({type:TestComponent,selector
}
(() =>{
(((typeof ngDevMode === "undefined") || ngDevMode) && i0.ɵsetClassDebugInfo(TestComponent,
{className:"TestComponent",filePath:"test.component.ts",lineNumber:1}));
{className:"TestComponent",filePath:"test.component.ts",lineNumber:9}));
})();
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({type:MyComponent,selectors:
}
(() =>{
(((typeof ngDevMode === "undefined") || ngDevMode) && i0.ɵsetClassDebugInfo(MyComponent,
{className:"MyComponent",filePath:"test.component.ts",lineNumber:1}));
{className:"MyComponent",filePath:"test.component.ts",lineNumber:22}));
})();
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({type:MyComponent,selectors:
}
(() =>{
(((typeof ngDevMode === "undefined") || ngDevMode) && i0.ɵsetClassDebugInfo(MyComponent,
{className:"MyComponent",filePath:"test.component.ts",lineNumber:1}));
{className:"MyComponent",filePath:"test.component.ts",lineNumber:22}));
})();
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
source: crates/oxc_angular_compiler/tests/integration_test.rs
expression: result.code
---

import { Component } from '@angular/core';
import * as i0 from '@angular/core';

Expand Down Expand Up @@ -33,5 +34,5 @@ static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({type:TestComponent,selector
}
(() =>{
(((typeof ngDevMode === "undefined") || ngDevMode) && i0.ɵsetClassDebugInfo(TestComponent,
{className:"TestComponent",filePath:"test.component.ts",lineNumber:1}));
{className:"TestComponent",filePath:"test.component.ts",lineNumber:9}));
})();
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({type:BadgeComponent,selecto
}
(() =>{
(((typeof ngDevMode === "undefined") || ngDevMode) && i0.ɵsetClassDebugInfo(BadgeComponent,
{className:"BadgeComponent",filePath:"badge.component.ts",lineNumber:1}));
{className:"BadgeComponent",filePath:"badge.component.ts",lineNumber:9}));
})();
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
source: crates/oxc_angular_compiler/tests/integration_test.rs
expression: result.code
---

import { Component } from '@angular/core';
import * as i0 from '@angular/core';

Expand Down Expand Up @@ -46,5 +47,5 @@ static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({type:ExternalComponent,sele
}
(() =>{
(((typeof ngDevMode === "undefined") || ngDevMode) && i0.ɵsetClassDebugInfo(ExternalComponent,
{className:"ExternalComponent",filePath:"test.component.ts",lineNumber:1}));
{className:"ExternalComponent",filePath:"test.component.ts",lineNumber:9}));
})();
Loading