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

Function checkGrammarStatementInAmbientContext

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

Source from the content-addressed store, hash-verified

89025 return !!(node.flags & 16777216 /* NodeFlags.Ambient */) && checkGrammarTopLevelElementsForRequiredDeclareModifier(node);
89026 }
89027 function checkGrammarStatementInAmbientContext(node) {
89028 if (node.flags & 16777216 /* NodeFlags.Ambient */) {
89029 // Find containing block which is either Block, ModuleBlock, SourceFile
89030 var links = getNodeLinks(node);
89031 if (!links.hasReportedStatementInAmbientContext && (ts.isFunctionLike(node.parent) || ts.isAccessor(node.parent))) {
89032 return getNodeLinks(node).hasReportedStatementInAmbientContext = grammarErrorOnFirstToken(node, ts.Diagnostics.An_implementation_cannot_be_declared_in_ambient_contexts);
89033 }
89034 // We are either parented by another statement, or some sort of block.
89035 // If we're in a block, we only want to really report an error once
89036 // to prevent noisiness. So use a bit on the block to indicate if
89037 // this has already been reported, and don't report if it has.
89038 //
89039 if (node.parent.kind === 235 /* SyntaxKind.Block */ || node.parent.kind === 262 /* SyntaxKind.ModuleBlock */ || node.parent.kind === 305 /* SyntaxKind.SourceFile */) {
89040 var links_2 = getNodeLinks(node.parent);
89041 // Check if the containing block ever report this error
89042 if (!links_2.hasReportedStatementInAmbientContext) {
89043 return links_2.hasReportedStatementInAmbientContext = grammarErrorOnFirstToken(node, ts.Diagnostics.Statements_are_not_allowed_in_ambient_contexts);
89044 }
89045 }
89046 else {
89047 // We must be parented by a statement. If so, there's no need
89048 // to report the error as our parent will have already done it.
89049 // Debug.assert(isStatement(node.parent));
89050 }
89051 }
89052 return false;
89053 }
89054 function checkGrammarNumericLiteral(node) {
89055 // Grammar checking
89056 if (node.numericLiteralFlags & 32 /* TokenFlags.Octal */) {

Callers 15

checkBlockFunction · 0.85
checkExpressionStatementFunction · 0.85
checkIfStatementFunction · 0.85
checkDoStatementFunction · 0.85
checkWhileStatementFunction · 0.85
checkForStatementFunction · 0.85
checkReturnStatementFunction · 0.85
checkWithStatementFunction · 0.85
checkSwitchStatementFunction · 0.85
checkLabeledStatementFunction · 0.85
checkThrowStatementFunction · 0.85

Calls 2

getNodeLinksFunction · 0.85
grammarErrorOnFirstTokenFunction · 0.85

Tested by

no test coverage detected