-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(module-federation): Throw an error if remote is invalid
closes: #23024
- Loading branch information
1 parent
bf90604
commit 06b2fd9
Showing
7 changed files
with
104 additions
and
0 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
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,37 @@ | ||
/** | ||
* Determines if a given string is a valid JavaScript variable name. | ||
* @param name name of the variable to be checked | ||
* @returns result object with a boolean indicating if the name is valid and a message explaining why it is not valid | ||
*/ | ||
export function isValidVariable(name: string): { | ||
isValid: boolean; | ||
message: string; | ||
} { | ||
const validRegex = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/; | ||
|
||
if (validRegex.test(name)) { | ||
return { isValid: true, message: 'The name is a valid identifier.' }; | ||
} else { | ||
if (name === '') { | ||
return { isValid: false, message: 'The name cannot be empty.' }; | ||
} else if (/^[0-9]/.test(name)) { | ||
return { isValid: false, message: 'The name cannot start with a digit.' }; | ||
} else if (/[^a-zA-Z0-9_$]/.test(name)) { | ||
return { | ||
isValid: false, | ||
message: | ||
'The name can only contain letters, digits, underscores, and dollar signs.', | ||
}; | ||
} else if (/^[^a-zA-Z_$]/.test(name)) { | ||
return { | ||
isValid: false, | ||
message: | ||
'The name must start with a letter, underscore, or dollar sign.', | ||
}; | ||
} | ||
return { | ||
isValid: false, | ||
message: 'The name is not a valid JavaScript identifier.', | ||
}; | ||
} | ||
} |
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