Your Name 056619c27f null
2024-03-15 14:39:48 +08:00

1 line
5.4 KiB
Plaintext

{"version":3,"names":["File","node","program","print","interpreter","Program","printInnerComments","printSequence","directives","length","newline","body","BlockStatement","token","hasDirectives","indent","removeTrailingNewline","source","loc","endsWith","rightBrace","Directive","value","semicolon","unescapedSingleQuoteRE","unescapedDoubleQuoteRE","DirectiveLiteral","raw","getPossibleRaw","format","minified","undefined","test","Error","InterpreterDirective","Placeholder","name","expectedNode"],"sources":["../../src/generators/base.ts"],"sourcesContent":["import type Printer from \"../printer\";\nimport type * as t from \"@babel/types\";\nimport * as charCodes from \"charcodes\";\n\nexport function File(this: Printer, node: t.File) {\n if (node.program) {\n // Print this here to ensure that Program node 'leadingComments' still\n // get printed after the hashbang.\n this.print(node.program.interpreter, node);\n }\n\n this.print(node.program, node);\n}\n\nexport function Program(this: Printer, node: t.Program) {\n this.printInnerComments(node, false);\n\n this.printSequence(node.directives, node);\n if (node.directives && node.directives.length) this.newline();\n\n this.printSequence(node.body, node);\n}\n\nexport function BlockStatement(this: Printer, node: t.BlockStatement) {\n this.token(\"{\");\n this.printInnerComments(node);\n\n const hasDirectives = node.directives?.length;\n\n if (node.body.length || hasDirectives) {\n this.newline();\n\n this.printSequence(node.directives, node, { indent: true });\n if (hasDirectives) this.newline();\n\n this.printSequence(node.body, node, { indent: true });\n this.removeTrailingNewline();\n\n this.source(\"end\", node.loc);\n\n if (!this.endsWith(charCodes.lineFeed)) this.newline();\n\n this.rightBrace();\n } else {\n this.source(\"end\", node.loc);\n this.token(\"}\");\n }\n}\n\nexport function Directive(this: Printer, node: t.Directive) {\n this.print(node.value, node);\n this.semicolon();\n}\n\n// These regexes match an even number of \\ followed by a quote\nconst unescapedSingleQuoteRE = /(?:^|[^\\\\])(?:\\\\\\\\)*'/;\nconst unescapedDoubleQuoteRE = /(?:^|[^\\\\])(?:\\\\\\\\)*\"/;\n\nexport function DirectiveLiteral(this: Printer, node: t.DirectiveLiteral) {\n const raw = this.getPossibleRaw(node);\n if (!this.format.minified && raw !== undefined) {\n this.token(raw);\n return;\n }\n\n const { value } = node;\n\n // NOTE: In directives we can't change escapings,\n // because they change the behavior.\n // e.g. \"us\\x65 string\" (\\x65 is e) is not a \"use strict\" directive.\n\n if (!unescapedDoubleQuoteRE.test(value)) {\n this.token(`\"${value}\"`);\n } else if (!unescapedSingleQuoteRE.test(value)) {\n this.token(`'${value}'`);\n } else {\n throw new Error(\n \"Malformed AST: it is not possible to print a directive containing\" +\n \" both unescaped single and double quotes.\",\n );\n }\n}\n\nexport function InterpreterDirective(\n this: Printer,\n node: t.InterpreterDirective,\n) {\n this.token(`#!${node.value}\\n`, true);\n}\n\nexport function Placeholder(this: Printer, node: t.Placeholder) {\n this.token(\"%%\");\n this.print(node.name);\n this.token(\"%%\");\n\n if (node.expectedNode === \"Statement\") {\n this.semicolon();\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAIO,SAASA,IAAT,CAA6BC,IAA7B,EAA2C;EAChD,IAAIA,IAAI,CAACC,OAAT,EAAkB;IAGhB,KAAKC,KAAL,CAAWF,IAAI,CAACC,OAAL,CAAaE,WAAxB,EAAqCH,IAArC;EACD;;EAED,KAAKE,KAAL,CAAWF,IAAI,CAACC,OAAhB,EAAyBD,IAAzB;AACD;;AAEM,SAASI,OAAT,CAAgCJ,IAAhC,EAAiD;EACtD,KAAKK,kBAAL,CAAwBL,IAAxB,EAA8B,KAA9B;EAEA,KAAKM,aAAL,CAAmBN,IAAI,CAACO,UAAxB,EAAoCP,IAApC;EACA,IAAIA,IAAI,CAACO,UAAL,IAAmBP,IAAI,CAACO,UAAL,CAAgBC,MAAvC,EAA+C,KAAKC,OAAL;EAE/C,KAAKH,aAAL,CAAmBN,IAAI,CAACU,IAAxB,EAA8BV,IAA9B;AACD;;AAEM,SAASW,cAAT,CAAuCX,IAAvC,EAA+D;EAAA;;EACpE,KAAKY,SAAL;EACA,KAAKP,kBAAL,CAAwBL,IAAxB;EAEA,MAAMa,aAAa,uBAAGb,IA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