mirror of
https://github.com/danbulant/oxc
synced 2026-05-25 12:51:57 +00:00
feat(oxc_transformer): use better diagnostic message for ReplaceGlobalDefinesPlugin (#7439)
When I was handling plugin-related diagnostics in `rolldown`, I encountered this issue. If there is a define key like `a.6.b`, the error message states that <code>\`a.6.b\` is not an identifier</code>. However, it should actually be that <code>\`6\` is not an identifier</code>.
This commit is contained in:
parent
9558087db9
commit
d8c093126d
1 changed files with 7 additions and 3 deletions
|
|
@ -137,7 +137,9 @@ impl ReplaceGlobalDefinesConfig {
|
||||||
|
|
||||||
if parts.len() == 1 {
|
if parts.len() == 1 {
|
||||||
if !is_identifier_name(parts[0]) {
|
if !is_identifier_name(parts[0]) {
|
||||||
return Err(vec![OxcDiagnostic::error(format!("`{key}` is not an identifier."))]);
|
return Err(vec![OxcDiagnostic::error(format!(
|
||||||
|
"The define key `{key}` is not an identifier."
|
||||||
|
))]);
|
||||||
}
|
}
|
||||||
return Ok(IdentifierType::Identifier);
|
return Ok(IdentifierType::Identifier);
|
||||||
}
|
}
|
||||||
|
|
@ -148,7 +150,9 @@ impl ReplaceGlobalDefinesConfig {
|
||||||
|
|
||||||
for part in &parts[0..normalized_parts_len] {
|
for part in &parts[0..normalized_parts_len] {
|
||||||
if !is_identifier_name(part) {
|
if !is_identifier_name(part) {
|
||||||
return Err(vec![OxcDiagnostic::error(format!("`{key}` is not an identifier."))]);
|
return Err(vec![OxcDiagnostic::error(format!(
|
||||||
|
"The define key `{key}` contains an invalid identifier `{part}`."
|
||||||
|
))]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if is_import_meta {
|
if is_import_meta {
|
||||||
|
|
@ -167,7 +171,7 @@ impl ReplaceGlobalDefinesConfig {
|
||||||
// StaticMemberExpression with postfix wildcard
|
// StaticMemberExpression with postfix wildcard
|
||||||
} else if normalized_parts_len != parts.len() {
|
} else if normalized_parts_len != parts.len() {
|
||||||
Err(vec![OxcDiagnostic::error(
|
Err(vec![OxcDiagnostic::error(
|
||||||
"postfix wildcard is only allowed for `import.meta`.".to_string(),
|
"The postfix wildcard is only allowed for `import.meta`.".to_string(),
|
||||||
)])
|
)])
|
||||||
} else {
|
} else {
|
||||||
Ok(IdentifierType::DotDefines {
|
Ok(IdentifierType::DotDefines {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue