mirror of
https://github.com/denoland/deno.git
synced 2024-12-12 10:37:52 -05:00
12 lines
2.1 MiB
JavaScript
12 lines
2.1 MiB
JavaScript
|
// This file is copied from prettier@1.16.1
|
||
|
/**
|
||
|
* Copyright © James Long and contributors
|
||
|
*
|
||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||
|
*
|
||
|
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||
|
*
|
||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||
|
*/
|
||
|
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e.prettierPlugins=e.prettierPlugins||{},e.prettierPlugins.typescript=t())}(globalThis,function(){"use strict";var e=function(e,t){var r=new SyntaxError(e+" ("+t.start.line+":"+t.start.column+")");return r.loc=t,r};var t=function(e,t){if(e.startsWith("#!")){var r=e.indexOf("\n"),n={type:"Line",value:e.slice(2,r),range:[0,r],loc:{source:null,start:{line:1,column:0},end:{line:1,column:r}}};t.comments=[n].concat(t.comments)}},r="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function n(){throw new Error("Dynamic requires are not currently supported by rollup-plugin-commonjs")}function i(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function a(e,t){return e(t={exports:{}},t.exports),t.exports}var o=a(function(e){e.exports=function(e){if("string"!=typeof e)throw new TypeError("Expected a string");var t=e.match(/(?:\r?\n)/g)||[];if(0===t.length)return null;var r=t.filter(function(e){return"\r\n"===e}).length;return r>t.length-r?"\r\n":"\n"},e.exports.graceful=function(t){return e.exports(t)||"\n"}}),s={EOL:"\n"},c=Object.freeze({default:s}),u=c&&s||c,l=a(function(e,t){var r,n;function i(){return r=(e=o)&&e.__esModule?e:{default:e};var e}function a(){return n=u}Object.defineProperty(t,"__esModule",{value:!0}),t.extract=function(e){var t=e.match(l);return t?t[0].trimLeft():""},t.strip=function(e){var t=e.match(l);return t&&t[0]?e.substring(t[0].length):e},t.parse=function(e){return g(e).pragmas},t.parseWithComments=g,t.print=function(e){var t=e.comments,o=void 0===t?"":t,s=e.pragmas,c=void 0===s?{}:s,u=(0,(r||i()).default)(o)||(n||a()).EOL,l=Object.keys(c),_=l.map(function(e){return y(e,c[e])}).reduce(function(e,t){return e.concat(t)},[]).map(function(e){return" * "+e+u}).join("");if(!o){if(0===l.length)return"";if(1===l.length&&!Array.isArray(c[l[0]])){var d=c[l[0]];return"".concat("/**"," ").concat(y(l[0],d)[0]).concat(" */")}}var p=o.split(u).map(function(e){return"".concat(" *"," ").concat(e)}).join(u)+u;return"/**"+u+(o?p:"")+(o&&l.length?" *"+u:"")+_+" */"};var s=/\*\/$/,c=/^\/\*\*/,l=/^\s*(\/\*\*?(.|\r?\n)*?\*\/)/,_=/(^|\s+)\/\/([^\r\n]*)/g,d=/^(\r?\n)+/,p=/(?:^|\r?\n) *(@[^\r\n]*?) *\r?\n *(?![^@\r\n]*\/\/[^]*)([^@\r\n\s][^@\r\n]+?) *\r?\n/g,f=/(?:^|\r?\n) *@(\S+) *([^\r\n]*)/g,m=/(\r?\n|^) *\* ?/g;function g(e){var t=(0,(r||i()).default)(e)||(n||a()).EOL;e=e.replace(c,"").replace(s,"").replace(m,"$1");for(var o="";o!==e;)o=e,e=e.replace(p,"".concat(t,"$1 $2").concat(t));e=e.replace(d,"").trimRight();for(var u,l=Object.create(null),g=e.replace(f,"").replace(d,"").trimRight();u=f.exec(e);){var y=u[2].replace(_,"");"string"==typeof l[u[1]]||Array.isArray(l[u[1]])?l[u[1]]=[].concat(l[u[1]],y):l[u[1]]=y}return{comments:g,pragmas:l}}function y(e,t){return[].concat(t).map(function(t){return"@".concat(e," ").concat(t).trim()})}});i(l);var _=function(e){var t=Object.keys(l.parse(l.extract(e)));return-1!==t.indexOf("prettier")||-1!==t.indexOf("format")},d=function(e){return e.length>0?e[e.length-1]:null};var p={locStart:function e(t,r){return!(r=r||{}).ignoreDecorators&&t.declaration&&t.declaration.decorators&&t.declaration.decorators.length>0?e(t.declaration.decorators[0]):!r.ignoreDecorators&&t.decorators&&t.decorators.length>0?e(t.decorators[0]):t.__location?t.__location.startOffset:t.range?t.range[0]:"number"==typeof t.start?t.start:t.loc?t.loc.start:null},locEnd:function e(t){var r=t.nodes&&d(t.nodes);if(r&&t.source&&!t.source.end&&(t=r),t.__location)return t.__location.endOffset;var n=t.range?t.range[1]:"number"==typeof t.end?t.end:null;return t.typeAnnotation?Math.max(n,e(t.typeAnnotation)):t.loc&&!n?t.loc.end:n}};function f(e){return(f="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function m(e,t,r){return t in e?Object.defineProperty(e,t
|