-
-
Notifications
You must be signed in to change notification settings - Fork 502
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(isolated-declarations): improve the inference template literal (#…
- Loading branch information
Showing
7 changed files
with
79 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use oxc_allocator::Box; | ||
use oxc_ast::ast::{StringLiteral, TemplateLiteral}; | ||
|
||
use crate::IsolatedDeclarations; | ||
|
||
impl<'a> IsolatedDeclarations<'a> { | ||
pub fn transform_template_to_string( | ||
&self, | ||
lit: &TemplateLiteral<'a>, | ||
) -> Option<Box<'a, StringLiteral<'a>>> { | ||
if lit.expressions.is_empty() { | ||
lit.quasis.first().map(|item| { | ||
self.ast.alloc(self.ast.string_literal( | ||
lit.span, | ||
if let Some(cooked) = &item.value.cooked { cooked } else { &item.value.raw }, | ||
)) | ||
}) | ||
} else { | ||
None | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
crates/oxc_isolated_declarations/tests/fixtures/infer-template-literal.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export const CSS_VARS_HELPER = `useCssVars` | ||
|
||
export function g(func = `useCssVar`) : void {} | ||
|
||
export const F = { | ||
a: `a`, | ||
b: [`b`] | ||
} as const | ||
|
||
export const BAD = `useCssV${v}ars` |
24 changes: 24 additions & 0 deletions
24
crates/oxc_isolated_declarations/tests/snapshots/infer-template-literal.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- | ||
source: crates/oxc_isolated_declarations/tests/mod.rs | ||
input_file: crates/oxc_isolated_declarations/tests/fixtures/infer-template-literal.ts | ||
--- | ||
==================== .D.TS ==================== | ||
|
||
export declare const CSS_VARS_HELPER = 'useCssVars'; | ||
export declare function g(func?: string): void; | ||
export declare const F: { | ||
readonly a: 'a'; | ||
readonly b: readonly ['b']; | ||
}; | ||
export declare const BAD: unknown; | ||
|
||
|
||
==================== Errors ==================== | ||
|
||
x TS9010: Variable must have an explicit type annotation with | ||
| --isolatedDeclarations. | ||
,-[10:14] | ||
9 | | ||
10 | export const BAD = `useCssV${v}ars` | ||
: ^^^ | ||
`---- |