MCPcopy Create free account
hub / github.com/nodejs/node / checkGrammarNumericLiteral

Function checkGrammarNumericLiteral

test/fixtures/snapshot/typescript.js:89054–89076  ·  view source on GitHub ↗
(node)

Source from the content-addressed store, hash-verified

89052 return false;
89053 }
89054 function checkGrammarNumericLiteral(node) {
89055 // Grammar checking
89056 if (node.numericLiteralFlags & 32 /* TokenFlags.Octal */) {
89057 var diagnosticMessage = void 0;
89058 if (languageVersion >= 1 /* ScriptTarget.ES5 */) {
89059 diagnosticMessage = ts.Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher_Use_the_syntax_0;
89060 }
89061 else if (ts.isChildOfNodeWithKind(node, 196 /* SyntaxKind.LiteralType */)) {
89062 diagnosticMessage = ts.Diagnostics.Octal_literal_types_must_use_ES2015_syntax_Use_the_syntax_0;
89063 }
89064 else if (ts.isChildOfNodeWithKind(node, 299 /* SyntaxKind.EnumMember */)) {
89065 diagnosticMessage = ts.Diagnostics.Octal_literals_are_not_allowed_in_enums_members_initializer_Use_the_syntax_0;
89066 }
89067 if (diagnosticMessage) {
89068 var withMinus = ts.isPrefixUnaryExpression(node.parent) && node.parent.operator === 40 /* SyntaxKind.MinusToken */;
89069 var literal = (withMinus ? "-" : "") + "0o" + node.text;
89070 return grammarErrorOnNode(withMinus ? node.parent : node, diagnosticMessage, literal);
89071 }
89072 }
89073 // Realism (size) checking
89074 checkNumericLiteralValueSize(node);
89075 return false;
89076 }
89077 function checkNumericLiteralValueSize(node) {
89078 // We should test against `getTextOfNode(node)` rather than `node.text`, because `node.text` for large numeric literals can contain "."
89079 // e.g. `node.text` for numeric literal `1100000000000000000000` is `1.1e21`.

Callers 3

checkExpressionWorkerFunction · 0.85
evaluateFunction · 0.85

Calls 2

grammarErrorOnNodeFunction · 0.85

Tested by

no test coverage detected