webhook/node_modules/prettier/parser-angular.js

47 lines
48 KiB
JavaScript
Raw Normal View History

2020-08-27 10:23:33 +02:00
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):((t="undefined"!=typeof globalThis?globalThis:t||self).prettierPlugins=t.prettierPlugins||{},t.prettierPlugins.angular=e())}(this,(function(){"use strict";function t(e,s){const{ignoreDecorators:n}=s||{};if(!n){const s=e.declaration&&e.declaration.decorators||e.decorators;if(s&&s.length>0)return t(s[0])}return e.range?e.range[0]:e.start}function e(t){const s=t.range?t.range[1]:t.end;return t.typeAnnotation?Math.max(s,e(t.typeAnnotation)):s}var s={locStart:t,locEnd:e,composeLoc:function(s,n=s){const r=t(s);return[r,"number"==typeof n?r+n:e(n)]}};function n(t,e,s){return t(s={path:e,exports:{},require:function(t,e){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==e&&s.path)}},s.exports),s.exports}var r,i=n((function(t,e){var s=function(){function t(t){this.string=t;for(var e=[0],s=0;s<t.length;)switch(t[s]){case"\n":s+="\n".length,e.push(s);break;case"\r":"\n"===t[s+="\r".length]&&(s+="\n".length),e.push(s);break;default:s++}this.offsets=e}return t.prototype.locationForIndex=function(t){if(t<0||t>this.string.length)return null;for(var e=0,s=this.offsets;s[e+1]<=t;)e++;return{line:e,column:t-s[e]}},t.prototype.indexForLocation=function(t){var e=t.line,s=t.column;return e<0||e>=this.offsets.length||s<0||s>this.lengthOfLine(e)?null:this.offsets[e]+s},t.prototype.lengthOfLine=function(t){var e=this.offsets[t];return(t===this.offsets.length-1?this.string.length:this.offsets[t+1])-e},t}();e.__esModule=!0,e.default=s})),a=n((function(t,e){Object.defineProperty(e,"__esModule",{value:!0});e.Context=class{constructor(t){this.text=t,this.locator=new s(this.text)}};class s{constructor(t){this._lineAndColumn=new i.default(t)}locationForIndex(t){const{line:e,column:s}=this._lineAndColumn.locationForIndex(t);return{line:e+1,column:s}}}}));
/**
* @license
2020-08-27 10:23:33 +02:00
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
2020-08-27 10:23:33 +02:00
class o{constructor(t,e,s,n){this.input=e,this.errLocation=s,this.ctxLocation=n,this.message="Parser Error: ".concat(t," ").concat(s," [").concat(e,"] in ").concat(n)}}class c{constructor(t,e){this.start=t,this.end=e}toAbsolute(t){return new L(t+this.start,t+this.end)}}class h{constructor(t,e){this.span=t,this.sourceSpan=e}visit(t,e=null){return null}toString(){return"AST"}}class p extends h{constructor(t,e,s){super(t,e),this.nameSpan=s}}class u extends h{constructor(t,e,s,n,r){super(t,e),this.prefix=s,this.uninterpretedExpression=n,this.location=r}visit(t,e=null){return t.visitQuote(this,e)}toString(){return"Quote"}}class l extends h{visit(t,e=null){}}class d extends h{visit(t,e=null){return t.visitImplicitReceiver(this,e)}}class f extends h{constructor(t,e,s){super(t,e),this.expressions=s}visit(t,e=null){return t.visitChain(this,e)}}class v extends h{constructor(t,e,s,n,r){super(t,e),this.condition=s,this.trueExp=n,this.falseExp=r}visit(t,e=null){return t.visitConditional(this,e)}}class x extends p{constructor(t,e,s,n,r){super(t,e,s),this.receiver=n,this.name=r}visit(t,e=null){return t.visitPropertyRead(this,e)}}class g extends p{constructor(t,e,s,n,r,i){super(t,e,s),this.receiver=n,this.name=r,this.value=i}visit(t,e=null){return t.visitPropertyWrite(this,e)}}class m extends p{constructor(t,e,s,n,r){super(t,e,s),this.receiver=n,this.name=r}visit(t,e=null){return t.visitSafePropertyRead(this,e)}}class y extends h{constructor(t,e,s,n){super(t,e),this.obj=s,this.key=n}visit(t,e=null){return t.visitKeyedRead(this,e)}}class S extends h{constructor(t,e,s,n,r){super(t,e),this.obj=s,this.key=n,this.value=r}visit(t,e=null){return t.visitKeyedWrite(this,e)}}class w extends p{constructor(t,e,s,n,r,i){super(t,e,i),this.exp=s,this.name=n,this.args=r}visit(t,e=null){return t.visitPipe(this,e)}}class C extends h{constructor(t,e,s){super(t,e),this.value=s}visit(t,e=null){return t.visitLiteralPrimitive(this,e)}}class P extends h{constructor(t,e,s){super(t,e),this.expressions=s}visit(t,e=null){return t.visitLiteralArray(this,e)}}class E extends h{constructor(t,e,s,n){super(t,e),this.keys=s,this.values=n}visit(t,e=null){return t.visitLiteralMap(this,e)}}class A extends h{constructor(t,e,s,n){super(t,e),this.strings=s,this.expressions=n}visit(t,e=null){return t.visitInterpolation(this,e)}}class O extends h{constructor(t,e,s,n,r){super(t,e),this.operation=s,this.left=n,this.right=r}visit(t,e=null){return t.visitBinary(this,e)}}class b extends h{constructor(t,e,s){super(t,e),this.expression=s}visit(t,e=null){return t.visitPrefixNot(this,e)}}class k extends h{constructor(t,e,s){super(t,e),this.expression=s}visit(t,e=null){return t.visitNonNullAssert(this,e)}}class N extends p{constructor(t,e,s,n,r,i){super(t,e,s),this.receiver=n,this.name=r,this.args=i}visit(t,e=null){return t.visitMethodCall(this,e)}}class I extends p{constructor(t,e,s,n,r,i){super(t,e,s),this.receiver=n,this.name=r,this.args=i}visit(t,e=null){return t.visitSafeMethodCall(this,e)}}class _ extends h{constructor(t,e,s,n){super(t,e),this.target=s,this.args=n}visit(t,e=null){return t.visitFunctionCall(this,e)}}class L{constructor(t,e){this.start=t,this.end=e}}class K extends h{constructor(t,e,s,n,r){super(new c(0,null===e?0:e.length),new L(n,null===e?n:n+e.length)),this.ast=t,this.source=e,this.location=s,this.errors=r}visit(t,e=null){return t.visitASTWithSource?t.visitASTWithSource(this,e):this.ast.visit(t,e)}toString(){return"".concat(this.source," in ").concat(this.location)}}class M{constructor(t,e,s){this.sourceSpan=t,this.key=e,this.value=s}}class T{constructor(t,e,s){this.sourceSpan=t,this.key=e,this.value=s}}class B{visit(t,e){t.visit(this,e)}visitBinary(t,e){this.visit(t.left,e),this.visit(t.right,e)}visitChain(t,e){this.visitAll(t.expressions,e)}visitConditional(t,e){this.visit(t.condition,e),this.visit(t.trueExp,e),this.visit(t.falseExp,e)}visitPipe(t,e){this.visit(t.exp,e),this.visitAll(t.args,e)}visitFunctionCall(t,e){t.target&&this.visit(t.target,e),this.visitAll(t.args,e)}visitImplicitReceiver(t,e){}visitInterpolation(t,e){this.visitAll(t.expressions,e)}visitKey
/**
* @license
2020-08-27 10:23:33 +02:00
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
2020-08-27 10:23:33 +02:00
*/function j(t){return 48<=t&&t<=57}
/**
* @license
2020-08-27 10:23:33 +02:00
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
2020-08-27 10:23:33 +02:00
var F;!function(t){t[t.Character=0]="Character",t[t.Identifier=1]="Identifier",t[t.Keyword=2]="Keyword",t[t.String=3]="String",t[t.Operator=4]="Operator",t[t.Number=5]="Number",t[t.Error=6]="Error"}(F||(F={}));const G=["var","let","as","null","undefined","true","false","if","else","this"];class V{constructor(t,e,s,n,r){this.index=t,this.end=e,this.type=s,this.numValue=n,this.strValue=r}isCharacter(t){return this.type==F.Character&&this.numValue==t}isNumber(){return this.type==F.Number}isString(){return this.type==F.String}isOperator(t){return this.type==F.Operator&&this.strValue==t}isIdentifier(){return this.type==F.Identifier}isKeyword(){return this.type==F.Keyword}isKeywordLet(){return this.type==F.Keyword&&"let"==this.strValue}isKeywordAs(){return this.type==F.Keyword&&"as"==this.strValue}isKeywordNull(){return this.type==F.Keyword&&"null"==this.strValue}isKeywordUndefined(){return this.type==F.Keyword&&"undefined"==this.strValue}isKeywordTrue(){return this.type==F.Keyword&&"true"==this.strValue}isKeywordFalse(){return this.type==F.Keyword&&"false"==this.strValue}isKeywordThis(){return this.type==F.Keyword&&"this"==this.strValue}isError(){return this.type==F.Error}toNumber(){return this.type==F.Number?this.numValue:-1}toString(){switch(this.type){case F.Character:case F.Identifier:case F.Keyword:case F.Operator:case F.String:case F.Error:return this.strValue;case F.Number:return this.numValue.toString();default:return null}}}function W(t,e,s){return new V(t,e,F.Character,s,String.fromCharCode(s))}function U(t,e,s){return new V(t,e,F.Operator,0,s)}const Q=new V(-1,-1,F.Character,0,"");class D{constructor(t){this.input=t,this.peek=0,this.index=-1,this.length=t.length,this.advance()}advance(){this.peek=++this.index>=this.length?0:this.input.charCodeAt(this.index)}scanToken(){const t=this.input,e=this.length;let s=this.peek,n=this.index;for(;s<=32;){if(++n>=e){s=0;break}s=t.charCodeAt(n)}if(this.peek=s,this.index=n,n>=e)return null;if(z(s))return this.scanIdentifier();if(j(s))return this.scanNumber(n);const r=n;switch(s){case 46:return this.advance(),j(this.peek)?this.scanNumber(r):W(r,this.index,46);case 40:case 41:case 123:case 125:case 91:case 93:case 44:case 58:case 59:return this.scanCharacter(r,s);case 39:case 34:return this.scanString();case 35:case 43:case 45:case 42:case 47:case 37:case 94:return this.scanOperator(r,String.fromCharCode(s));case 63:return this.scanComplexOperator(r,"?",46,".");case 60:case 62:return this.scanComplexOperator(r,String.fromCharCode(s),61,"=");case 33:case 61:return this.scanComplexOperator(r,String.fromCharCode(s),61,"=",61,"=");case 38:return this.scanComplexOperator(r,"&",38,"&");case 124:return this.scanComplexOperator(r,"|",124,"|");case 160:for(;(i=this.peek)>=9&&i<=32||160==i;)this.advance();return this.scanToken()}var i;return this.advance(),this.error("Unexpected character [".concat(String.fromCharCode(s),"]"),0)}scanCharacter(t,e){return this.advance(),W(t,this.index,e)}scanOperator(t,e){return this.advance(),U(t,this.index,e)}scanComplexOperator(t,e,s,n,r,i){this.advance();let a=e;return this.peek==s&&(this.advance(),a+=n),null!=r&&this.peek==r&&(this.advance(),a+=i),U(t,this.index,a)}scanIdentifier(){const t=this.index;for(this.advance();$(this.peek);)this.advance();const e=this.input.substring(t,this.index);return G.indexOf(e)>-1?(s=t,n=this.index,r=e,new V(s,n,F.Keyword,0,r)):function(t,e,s){return new V(t,e,F.Identifier,0,s)}(t,this.index,e);var s,n,r}scanNumber(t){let e=this.index===t;for(this.advance();;){if(j(this.peek));else if(46==this.peek)e=!1;else{if(101!=(s=this.peek)&&69!=s)break;if(this.advance(),X(this.peek)&&this.advance(),!j(this.peek))return this.error("Invalid exponent",-1);e=!1}this.advance()}var s;const n=this.input.substring(t,this.index),r=e?function(t){const e=parseInt(t);if(isNaN(e))throw new Error("Invalid integer literal when parsing "+t);return e}(n):parseFloat(n);return i=t,a=this.index,o=r,new V(i,a,F.Number,o,"");var i,a,o}scanString(){const t=this.index,e=this.peek;this.advance();let s="",n=this.index;const r=this.input;for(;this.peek!=e;)i
/**
* @license
2020-08-27 10:23:33 +02:00
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
2020-08-27 10:23:33 +02:00
*/const Z=[/^\s*$/,/[<>]/,/^[{}]$/,/&(#|[a-z])/i,/^\/\//];
/**
* @license
2020-08-27 10:23:33 +02:00
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
2020-08-27 10:23:33 +02:00
class tt{constructor(t,e){this.start=t,this.end=e}static fromArray(t){return t?(function(t,e){if(!(null==e||Array.isArray(e)&&2==e.length))throw new Error("Expected '".concat(t,"' to be an array, [start, end]."));if(null!=e){const t=e[0],s=e[1];Z.forEach(e=>{if(e.test(t)||e.test(s))throw new Error("['".concat(t,"', '").concat(s,"'] contains unusable interpolation symbol."))})}}("interpolation",t),new tt(t[0],t[1])):et}}const et=new tt("{{","}}");function st(t){return t.replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")}"undefined"!=typeof self&&"undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope&&self;
/**
* @license
2020-08-27 10:23:33 +02:00
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
2020-08-27 10:23:33 +02:00
*/class nt{constructor(t,e,s){this.strings=t,this.expressions=e,this.offsets=s}}class rt{constructor(t,e,s){this.templateBindings=t,this.warnings=e,this.errors=s}}const it=ot(et);function at(t){return t===et?it:ot(t)}function ot(t){const e=st(t.start)+"([\\s\\S]*?)"+st(t.end);return new RegExp(e,"g")}class ct{constructor(t){this._lexer=t,this.errors=[],this.simpleExpressionChecker=pt}parseAction(t,e,s,n=et){this._checkNoInterpolation(t,e,n);const r=this._stripComments(t),i=this._lexer.tokenize(this._stripComments(t)),a=new ht(t,e,s,i,r.length,!0,this.errors,t.length-r.length).parseChain();return new K(a,t,e,s,this.errors)}parseBinding(t,e,s,n=et){const r=this._parseBindingAst(t,e,s,n);return new K(r,t,e,s,this.errors)}checkSimpleExpression(t){const e=new this.simpleExpressionChecker;return t.visit(e),e.errors}parseSimpleBinding(t,e,s,n=et){const r=this._parseBindingAst(t,e,s,n),i=this.checkSimpleExpression(r);return i.length>0&&this._reportError("Host binding expression cannot contain ".concat(i.join(" ")),t,e),new K(r,t,e,s,this.errors)}_reportError(t,e,s,n){this.errors.push(new o(t,e,s,n))}_parseBindingAst(t,e,s,n){const r=this._parseQuote(t,e,s);if(null!=r)return r;this._checkNoInterpolation(t,e,n);const i=this._stripComments(t),a=this._lexer.tokenize(i);return new ht(t,e,s,a,i.length,!1,this.errors,t.length-i.length).parseChain()}_parseQuote(t,e,s){if(null==t)return null;const n=t.indexOf(":");if(-1==n)return null;const r=t.substring(0,n).trim();if(!q(r))return null;const i=t.substring(n+1),a=new c(0,t.length);return new u(a,a.toAbsolute(s),r,i,e)}parseTemplateBindings(t,e,s,n,r){const i=this._lexer.tokenize(e);return new ht(e,s,r,i,e.length,!1,this.errors,0).parseTemplateBindings({source:t,span:new L(n,n+t.length)})}parseInterpolation(t,e,s,n=et){const r=this.splitInterpolation(t,e,n);if(null==r)return null;const i=[];for(let n=0;n<r.expressions.length;++n){const a=r.expressions[n],o=this._stripComments(a),c=this._lexer.tokenize(o),h=new ht(t,e,s,c,o.length,!1,this.errors,r.offsets[n]+(a.length-o.length)).parseChain();i.push(h)}const a=new c(0,null==t?0:t.length);return new K(new A(a,a.toAbsolute(s),r.strings,i),t,e,s,this.errors)}splitInterpolation(t,e,s=et){const n=at(s),r=t.split(n);if(r.length<=1)return null;const i=[],a=[],o=[];let c=0;for(let n=0;n<r.length;n++){const h=r[n];n%2==0?(i.push(h),c+=h.length):h.trim().length>0?(c+=s.start.length,a.push(h),o.push(c),c+=h.length+s.end.length):(this._reportError("Blank expressions are not allowed in interpolated strings",t,"at column ".concat(this._findInterpolationErrorColumn(r,n,s)," in"),e),a.push("$implicit"),o.push(c))}return new nt(i,a,o)}wrapLiteralPrimitive(t,e,s){const n=new c(0,null==t?0:t.length);return new K(new C(n,n.toAbsolute(s),t),t,e,s,this.errors)}_stripComments(t){const e=this._commentStart(t);return null!=e?t.substring(0,e).trim():t}_commentStart(t){let e=null;for(let s=0;s<t.length-1;s++){const n=t.charCodeAt(s),r=t.charCodeAt(s+1);if(47===n&&47==r&&null==e)return s;e===n?e=null:null==e&&J(n)&&(e=n)}return null}_checkNoInterpolation(t,e,s){const n=at(s),r=t.split(n);r.length>1&&this._reportError("Got interpolation (".concat(s.start).concat(s.end,") where expression was expected"),t,"at column ".concat(this._findInterpolationErrorColumn(r,1,s)," in"),e)}_findInterpolationErrorColumn(t,e,s){let n="";for(let r=0;r<e;r++)n+=r%2==0?t[r]:"".concat(s.start).concat(t[r]).concat(s.end);return n.length}}class ht{constructor(t,e,s,n,r,i,a,o){this.input=t,this.location=e,this.absoluteOffset=s,this.tokens=n,this.inputLength=r,this.parseAction=i,this.errors=a,this.offset=o,this.rparensExpected=0,this.rbracketsExpected=0,this.rbracesExpected=0,this.sourceSpanCache=new Map,this.index=0}peek(t){const e=this.index+t;return e<this.tokens.length?this.tokens[e]:Q}get next(){return this.peek(0)}get atEOF(){return this.index>=this.tokens.length}get inputIndex(){return this.atEOF?this.currentEndIndex:this.next.index+this.offset}get currentEndIndex(){if(this.index>0){return this.peek(-1).end+this.offset}return 0===this.tokens.length?this.inputLength+this.offset:this.