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
2 changes: 2 additions & 0 deletions apps/oxfmt/src/core/external_formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ fn language_to_prettier_parser(language: &str) -> Option<&'static str> {
"tagged-graphql" => Some("graphql"),
"tagged-html" => Some("html"),
"tagged-markdown" => Some("markdown"),
"angular-template" => Some("angular"),
"angular-styles" => Some("scss"),
_ => None,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,113 @@ var(--color),
--------------------"
`;

exports[`embedded_languages > css > should format (auto) 1`] = `
exports[`embedded_languages > angular.ts > should format (auto) 1`] = `
"--- FILE -----------
angular.ts
--- BEFORE ---------
// Angular @Component decorator - direct template and styles
// Uses Angular-specific syntax: interpolation, directives, bindings
@Component({
selector: 'app-root',
template: \`
<h1>{{ title }}</h1>
<div *ngIf="isVisible" [class.active]="isActive" (click)="onClick()">
<span>{{ count }}</span>
</div>
<ul><li *ngFor="let item of items">{{item.name}}</li></ul>
\`,
styles: \`h1 { color: blue }\`
})
export class AppComponent1 {}

// Array form styles
@Component({
selector: 'app-test',
template: \`<ul> <li>test</li>
</ul>
\`,
styles: [ \`

:host {
color: red;
}
div { background: blue
}
\`

]
})
class TestComponent {}

// Computed properties - should NOT be formatted
const styles = "foobar";
const template = "foobar";

@Component({
selector: 'app-computed',
[template]: \`<h1>{{ hello }}</h1>\`,
[styles]: \`h1 { color: blue }\`
})
export class AppComponent2 {}

--- AFTER ----------
// Angular @Component decorator - direct template and styles
// Uses Angular-specific syntax: interpolation, directives, bindings
@Component({
selector: "app-root",
template: \`
<h1>{{ title }}</h1>
<div *ngIf="isVisible" [class.active]="isActive" (click)="onClick()">
<span>{{ count }}</span>
</div>
<ul>
<li *ngFor="let item of items">{{ item.name }}</li>
</ul>
\`,
styles: \`
h1 {
color: blue;
}
\`,
})
export class AppComponent1 {}

// Array form styles
@Component({
selector: "app-test",
template: \`
<ul>
<li>test</li>
</ul>
\`,
styles: [
\`
:host {
color: red;
}
div {
background: blue;
}
\`,
],
})
class TestComponent {}

// Computed properties - should NOT be formatted
const styles = "foobar";
const template = "foobar";

@Component({
selector: "app-computed",
[template]: \`<h1>{{ hello }}</h1>\`,
[styles]: \`h1 { color: blue }\`,
})
export class AppComponent2 {}

--------------------"
`;

exports[`embedded_languages > css.js > should format (auto) 1`] = `
"--- FILE -----------
css.js
--- BEFORE ---------
Expand Down Expand Up @@ -227,7 +333,7 @@ const styledJsx = (
--------------------"
`;

exports[`embedded_languages > graphql > should format (auto) 1`] = `
exports[`embedded_languages > graphql.js > should format (auto) 1`] = `
"--- FILE -----------
graphql.js
--- BEFORE ---------
Expand Down Expand Up @@ -259,7 +365,7 @@ const mutation = graphql\`
--------------------"
`;

exports[`embedded_languages > html > should format (auto) 1`] = `
exports[`embedded_languages > html.js > should format (auto) 1`] = `
"--- FILE -----------
html.js
--- BEFORE ---------
Expand All @@ -284,7 +390,7 @@ const component = html\`
--------------------"
`;

exports[`embedded_languages > markdown > should format (auto) 1`] = `
exports[`embedded_languages > markdown.js > should format (auto) 1`] = `
"--- FILE -----------
markdown.js
--- BEFORE ---------
Expand Down Expand Up @@ -421,5 +527,101 @@ const readme = markdown\`##Installation
npm install package
\\\`\\\`\\\`\`;

--------------------

--- FILE -----------
angular.ts
--- BEFORE ---------
// Angular @Component decorator - direct template and styles
// Uses Angular-specific syntax: interpolation, directives, bindings
@Component({
selector: 'app-root',
template: \`
<h1>{{ title }}</h1>
<div *ngIf="isVisible" [class.active]="isActive" (click)="onClick()">
<span>{{ count }}</span>
</div>
<ul><li *ngFor="let item of items">{{item.name}}</li></ul>
\`,
styles: \`h1 { color: blue }\`
})
export class AppComponent1 {}

// Array form styles
@Component({
selector: 'app-test',
template: \`<ul> <li>test</li>
</ul>
\`,
styles: [ \`

:host {
color: red;
}
div { background: blue
}
\`

]
})
class TestComponent {}

// Computed properties - should NOT be formatted
const styles = "foobar";
const template = "foobar";

@Component({
selector: 'app-computed',
[template]: \`<h1>{{ hello }}</h1>\`,
[styles]: \`h1 { color: blue }\`
})
export class AppComponent2 {}

--- AFTER ----------
// Angular @Component decorator - direct template and styles
// Uses Angular-specific syntax: interpolation, directives, bindings
@Component({
selector: "app-root",
template: \`
<h1>{{ title }}</h1>
<div *ngIf="isVisible" [class.active]="isActive" (click)="onClick()">
<span>{{ count }}</span>
</div>
<ul><li *ngFor="let item of items">{{item.name}}</li></ul>
\`,
styles: \`h1 { color: blue }\`,
})
export class AppComponent1 {}

// Array form styles
@Component({
selector: "app-test",
template: \`<ul> <li>test</li>
</ul>
\`,
styles: [
\`

:host {
color: red;
}
div { background: blue
}
\`,
],
})
class TestComponent {}

// Computed properties - should NOT be formatted
const styles = "foobar";
const template = "foobar";

@Component({
selector: "app-computed",
[template]: \`<h1>{{ hello }}</h1>\`,
[styles]: \`h1 { color: blue }\`,
})
export class AppComponent2 {}

--------------------"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,21 @@ import { join } from "node:path";
import { runWriteModeAndSnapshot } from "../utils";

const fixturesDir = join(import.meta.dirname, "fixtures");
const languages = ["css", "graphql", "html", "markdown"] as const;
const languages = ["css.js", "graphql.js", "html.js", "markdown.js", "angular.ts"];

describe("embedded_languages", () => {
describe.each(languages)("%s", (lang) => {
it("should format (auto)", async () => {
const snapshot = await runWriteModeAndSnapshot(fixturesDir, [`${lang}.js`]);
const snapshot = await runWriteModeAndSnapshot(fixturesDir, [lang]);
expect(snapshot).toMatchSnapshot();
});
});

it("should not format any language (off)", async () => {
const snapshot = await runWriteModeAndSnapshot(
fixturesDir,
languages.map((lang) => `${lang}.js`),
["--config", "off_embedded.json"],
);
const snapshot = await runWriteModeAndSnapshot(fixturesDir, languages, [
"--config",
"off_embedded.json",
]);
expect(snapshot).toMatchSnapshot();
});

Expand Down
44 changes: 44 additions & 0 deletions apps/oxfmt/test/cli/embedded_languages/fixtures/angular.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Angular @Component decorator - direct template and styles
// Uses Angular-specific syntax: interpolation, directives, bindings
@Component({
selector: 'app-root',
template: `
<h1>{{ title }}</h1>
<div *ngIf="isVisible" [class.active]="isActive" (click)="onClick()">
<span>{{ count }}</span>
</div>
<ul><li *ngFor="let item of items">{{item.name}}</li></ul>
`,
styles: `h1 { color: blue }`
})
export class AppComponent1 {}

// Array form styles
@Component({
selector: 'app-test',
template: `<ul> <li>test</li>
</ul>
`,
styles: [ `

:host {
color: red;
}
div { background: blue
}
`

]
})
class TestComponent {}

// Computed properties - should NOT be formatted
const styles = "foobar";
const template = "foobar";

@Component({
selector: 'app-computed',
[template]: `<h1>{{ hello }}</h1>`,
[styles]: `h1 { color: blue }`
})
export class AppComponent2 {}
Loading
Loading