(identifierIsOptional?: boolean)
| 2855 | } |
| 2856 | |
| 2857 | parseFunctionDeclaration(identifierIsOptional?: boolean): Node.AsyncFunctionDeclaration | Node.FunctionDeclaration { |
| 2858 | const node = this.createNode(); |
| 2859 | |
| 2860 | const isAsync = this.matchContextualKeyword('async'); |
| 2861 | if (isAsync) { |
| 2862 | this.nextToken(); |
| 2863 | } |
| 2864 | |
| 2865 | this.expectKeyword('function'); |
| 2866 | |
| 2867 | const isGenerator = isAsync ? false : this.match('*'); |
| 2868 | if (isGenerator) { |
| 2869 | this.nextToken(); |
| 2870 | } |
| 2871 | |
| 2872 | let message; |
| 2873 | let id: Node.Identifier | null = null; |
| 2874 | let firstRestricted: RawToken | null = null; |
| 2875 | |
| 2876 | if (!identifierIsOptional || !this.match('(')) { |
| 2877 | const token = this.lookahead; |
| 2878 | id = this.parseVariableIdentifier(); |
| 2879 | if (this.context.strict) { |
| 2880 | if (this.scanner.isRestrictedWord(token.value as string)) { |
| 2881 | this.tolerateUnexpectedToken(token, Messages.StrictFunctionName); |
| 2882 | } |
| 2883 | } else { |
| 2884 | if (this.scanner.isRestrictedWord(token.value as string)) { |
| 2885 | firstRestricted = token; |
| 2886 | message = Messages.StrictFunctionName; |
| 2887 | } else if (this.scanner.isStrictModeReservedWord(token.value as string)) { |
| 2888 | firstRestricted = token; |
| 2889 | message = Messages.StrictReservedWord; |
| 2890 | } |
| 2891 | } |
| 2892 | } |
| 2893 | |
| 2894 | const previousAllowAwait = this.context.await; |
| 2895 | const previousAllowYield = this.context.allowYield; |
| 2896 | this.context.await = isAsync; |
| 2897 | this.context.allowYield = !isGenerator; |
| 2898 | |
| 2899 | const formalParameters = this.parseFormalParameters(firstRestricted); |
| 2900 | const params = formalParameters.params; |
| 2901 | const stricted = formalParameters.stricted; |
| 2902 | firstRestricted = formalParameters.firstRestricted; |
| 2903 | if (formalParameters.message) { |
| 2904 | message = formalParameters.message; |
| 2905 | } |
| 2906 | |
| 2907 | const previousStrict = this.context.strict; |
| 2908 | const previousAllowStrictDirective = this.context.allowStrictDirective; |
| 2909 | this.context.allowStrictDirective = formalParameters.simple; |
| 2910 | const body = this.parseFunctionSourceElements(); |
| 2911 | if (this.context.strict && firstRestricted) { |
| 2912 | this.throwUnexpectedToken(firstRestricted, message); |
| 2913 | } |
| 2914 | if (this.context.strict && stricted) { |
no test coverage detected