Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Dart spec reserved words #3984

Merged
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: 1 addition & 1 deletion lib/src/pubspec_parse.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ abstract class PubspecBase {
'"name" field must be a valid Dart identifier.',
fields.nodes['name']?.span,
);
} else if (reservedWords.contains(name)) {
} else if (reservedWords.contains(name.toLowerCase())) {
throw SourceSpanApplicationException(
'"name" field may not be a Dart reserved word.',
fields.nodes['name']?.span,
Expand Down
41 changes: 39 additions & 2 deletions lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,39 +29,76 @@ final identifierRegExp = RegExp(r'[a-zA-Z_]\w*');
final onlyIdentifierRegExp = RegExp('^${identifierRegExp.pattern}\$');

/// Dart reserved words, from the Dart spec.
const reservedWords = [
const reservedWords = <String>{
'abstract',
'as',
'assert',
// 'async', // Reserved, but allowed because package:async already exists.
'await',
// 'base', // Reserved, but allowed because package:base already exists.
'break',
'case',
'catch',
'class',
'const',
'continue',
'covariant',
'default',
'deferred',
'do',
// 'dynamic', // Reserved, but allowed because package:dynamic already exists.
'else',
'enum',
'export',
'extends',
// 'extension', // Reserved, but allowed because package:extension already exists.
'external',
// 'factory', // Reserved, but allowed because package:factory already exists.
'false',
'final',
'finally',
'for',
// 'get', // Reserved, but allowed because package:get already exists.
'hide',
'if',
'implements',
'import',
'in',
'inline',
'interface',
'is',
'late',
'library',
'mixin',
'new',
'null',
'of',
'on',
'operator',
'part',
'required',
'rethrow',
'return',
'sealed',
'set',
// 'show', // Reserved, but allowed because package:show already exists.
// 'static', // Reserved, but allowed because package:static already exists.
'super',
'switch',
// 'sync', // Reserved, but allowed because package:sync already exists.
'this',
'throw',
'true',
'try',
'type',
// 'typedef', // Reserved, but allowed because package:typedef already exists.
'var',
'void',
// 'when', // Reserved, but allowed because package:when already exists.
'while',
'with',
];
'yield',
};

/// An cryptographically secure instance of [math.Random].
final random = math.Random.secure();
Expand Down
Loading