How to use @marko/prettyprint - 3 common examples

To help you get started, we’ve selected a few @marko/prettyprint examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github marko-js / cli / packages / migrate / src / index.js View on Github external
},
              onUpdateDependents(from, to) {
                dependentUpdates.push(onUpdateDependents.bind(null, from, to));
              }
            });
          },
          migrate: true,
          raw: true
        });

        if (!options.safe) {
          await runAutoMigrations(migrateHelper);
        }

        let prettyOriginalSource;
        const migratedSource = markoPrettyprint.prettyPrintAST(
          ast,
          prettyPrintOptions
        );

        try {
          prettyOriginalSource = markoPrettyprint.prettyPrintSource(
            source,
            prettyPrintOptions
          );
        } catch (e) {
          // prettyprinting is only used to check if the template changed
          // if the original source fails to print for some reason, but the
          // migration was successful, that's fine.
        }

        if (
github marko-js / cli / packages / migrate / src / index.js View on Github external
migrate: true,
          raw: true
        });

        if (!options.safe) {
          await runAutoMigrations(migrateHelper);
        }

        let prettyOriginalSource;
        const migratedSource = markoPrettyprint.prettyPrintAST(
          ast,
          prettyPrintOptions
        );

        try {
          prettyOriginalSource = markoPrettyprint.prettyPrintSource(
            source,
            prettyPrintOptions
          );
        } catch (e) {
          // prettyprinting is only used to check if the template changed
          // if the original source fails to print for some reason, but the
          // migration was successful, that's fine.
        }

        if (
          migratedSource !== prettyOriginalSource ||
          fileNameUpdates.length ||
          dependentUpdates.length
        ) {
          await onWriteFile(file, migratedSource);
github marko-js / language-server / server / src / service.ts View on Github external
public onDocumentFormatting = ({
    textDocument,
    options
  }: DocumentFormattingParams): TextEdit[] => {
    const doc = this.documents.get(textDocument.uri)!;
    const { fsPath } = URI.parse(textDocument.uri);

    try {
      const text = doc.getText();
      const markoCompiler = loadMarkoFile(fsPath, "compiler");
      const CodeWriter = loadMarkoFile(fsPath, "compiler/CodeWriter");
      const formatted = prettyPrint(text, {
        markoCompiler,
        CodeWriter,
        filename: fsPath,
        indent: (options.insertSpaces ? " " : "\t").repeat(options.tabSize)
      });

      return [
        TextEdit.replace(
          Range.create(doc.positionAt(0), doc.positionAt(text.length)),
          formatted
        )
      ];
    } catch (e) {
      this.displayMessage("error", 'Formatting failed: "' + e.message + '"');
    }

@marko/prettyprint

Prettyprint Marko template files in the syntax of your choice

MIT
Latest version published 3 years ago

Package Health Score

48 / 100
Full package analysis