MCPcopy Create free account
hub / github.com/babel/babel / parseNewOrNewTarget

Function parseNewOrNewTarget

packages/babel-parser/src/parser/expression.ts:1954–1980  ·  view source on GitHub ↗
(this: Parser)

Source from the content-addressed store, hash-verified

1952 }
1953
1954 parseNewOrNewTarget(this: Parser): N.NewExpression | N.MetaProperty {
1955 const node = this.startNode<N.NewExpression | N.MetaProperty>();
1956 const isClassHeritageStart = this.state.start === this.classHeritageStart;
1957 this.next();
1958 if (isClassHeritageStart) this.classHeritageStart = this.state.start;
1959 if (this.match(tt.dot)) {
1960 // https://tc39.es/ecma262/#prod-NewTarget
1961 const meta = this.createIdentifier(
1962 this.startNodeAtNode<N.Identifier>(node),
1963 "new",
1964 );
1965 this.next();
1966 const metaProp = this.parseMetaProperty(
1967 node as Undone<N.MetaProperty>,
1968 meta,
1969 "target",
1970 );
1971
1972 if (!this.scope.allowNewTarget) {
1973 this.raise(Errors.UnexpectedNewTarget, metaProp);
1974 }
1975
1976 return metaProp;
1977 }
1978
1979 return this.parseNew(node as Undone<N.NewExpression>);
1980 }
1981
1982 // New's precedence is slightly tricky. It must allow its argument to
1983 // be a `[]` or dot subscript expression, but not a call — at least,

Callers

nothing calls this directly

Calls 2

nextMethod · 0.80
matchMethod · 0.80

Tested by

no test coverage detected