MCPcopy
hub / github.com/jquery/esprima / parseDirectivePrologues

Method parseDirectivePrologues

src/parser.ts:3009–3042  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3007 }
3008
3009 parseDirectivePrologues(): Node.Statement[] {
3010 let firstRestricted: RawToken | null = null;
3011
3012 const body: Node.Statement[] = [];
3013 while (true) {
3014 const token = this.lookahead;
3015 if (token.type !== Token.StringLiteral) {
3016 break;
3017 }
3018
3019 const statement = this.parseDirective();
3020 body.push(statement);
3021 const directive = (statement as Node.Directive).directive;
3022 if (typeof directive !== 'string') {
3023 break;
3024 }
3025
3026 if (directive === 'use strict') {
3027 this.context.strict = true;
3028 if (firstRestricted) {
3029 this.tolerateUnexpectedToken(firstRestricted, Messages.StrictOctalLiteral);
3030 }
3031 if (!this.context.allowStrictDirective) {
3032 this.tolerateUnexpectedToken(token, Messages.IllegalLanguageModeDirective);
3033 }
3034 } else {
3035 if (!firstRestricted && token.octal) {
3036 firstRestricted = token;
3037 }
3038 }
3039 }
3040
3041 return body;
3042 }
3043
3044 // https://tc39.github.io/ecma262/#sec-method-definitions
3045

Callers 3

parseModuleMethod · 0.95
parseScriptMethod · 0.95

Calls 3

parseDirectiveMethod · 0.95
pushMethod · 0.80

Tested by

no test coverage detected