├── .github └── ISSUE_TEMPLATE │ ├── Bug_report.yml │ └── config.yml ├── .gitignore ├── .gitmodules ├── .npmrc ├── .vscode ├── launch.json └── settings.json ├── CHANGELOG.md ├── LICENSE ├── README.md ├── crate ├── Cargo.lock ├── Cargo.toml ├── README.md └── src │ └── main.rs ├── extension ├── LICENSE ├── README.md ├── icon.png ├── package.json ├── src │ └── index.ts └── tsconfig.json ├── package.json ├── pnpm-lock.yaml ├── pnpm-workspace.yaml ├── scripts ├── build.ts ├── dev.format.ts ├── dev.repl.ts └── tsconfig.json ├── src ├── format │ ├── comments.ts │ ├── complexity.ts │ ├── core.ts │ ├── external.ts │ ├── plugin.ts │ ├── printer.ts │ └── styling.ts ├── index.ts ├── transform │ ├── custom │ │ ├── attribute.ts │ │ ├── cfg_if.ts │ │ └── utils.ts │ └── index.ts └── utils │ ├── common.ts │ └── debug.ts ├── tests ├── output-ext │ ├── errors │ │ └── foo.rs │ ├── expressions │ │ ├── block.f.rs │ │ ├── closure.f.rs │ │ ├── expr.f.rs │ │ ├── flow_expr.f.rs │ │ ├── ident.f.rs │ │ ├── literal.f.rs │ │ ├── match.f.rs │ │ ├── parens.f.rs │ │ ├── precedence.f.rs │ │ └── range.f.rs │ ├── features │ │ ├── arbitrary_enum_discriminant.f.rs │ │ ├── associated_type_bounds.f.rs │ │ ├── async_closure.f.rs │ │ ├── auto_traits.f.rs │ │ ├── const_generics_defaults.f.rs │ │ ├── const_trait_impl.f.rs │ │ ├── decl_macro.f.rs │ │ ├── destructuring_assignment.f.rs │ │ ├── generators.f.rs │ │ ├── if_let_guard.f.rs │ │ ├── inline_const.f.rs │ │ ├── inline_const_pat.f.rs │ │ ├── let_chains.f.rs │ │ ├── let_else.f.rs │ │ ├── negative_impls.f.rs │ │ └── trait_alias.f.rs │ ├── macro │ │ ├── attributes.f.rs │ │ ├── macro.invocation.f.rs │ │ ├── macro.item.f.rs │ │ ├── macro.match.f.rs │ │ ├── macro.tokens.f.rs │ │ └── macro.transform.f.rs │ ├── miscellaneous │ │ ├── ast-program-locs-attr-dangling.f.rs │ │ ├── ast-program-locs-attr.f.rs │ │ ├── ast-program-locs.f.rs │ │ ├── empty-attr-dangling-x.f.rs │ │ ├── empty-attr-dangling.f.rs │ │ ├── empty-attr-x.f.rs │ │ ├── empty-attr.f.rs │ │ ├── empty-comment-block-x.f.rs │ │ ├── empty-comment-block.f.rs │ │ ├── empty-comment-x.f.rs │ │ ├── empty-comment.f.rs │ │ ├── empty-doc-block-x.f.rs │ │ ├── empty-doc-block.f.rs │ │ ├── empty-doc-x.f.rs │ │ ├── empty-doc.f.rs │ │ ├── empty.f.rs │ │ ├── shebang-b.f.rs │ │ └── shebang.f.rs │ ├── patterns │ │ ├── pattern.f.rs │ │ ├── rest.f.rs │ │ └── union.f.rs │ ├── specifiers │ │ ├── extern.f.rs │ │ └── pub.f.rs │ ├── statements │ │ ├── const.f.rs │ │ ├── enum.f.rs │ │ ├── impl.f.rs │ │ ├── self.f.rs │ │ ├── spread.f.rs │ │ ├── statements.f.rs │ │ ├── static.f.rs │ │ ├── struct.f.rs │ │ ├── trait.f.rs │ │ ├── union.f.rs │ │ └── use.f.rs │ └── types │ │ ├── cast.f.rs │ │ ├── never.f.rs │ │ └── types.f.rs ├── output │ ├── comments │ │ ├── assignment.f.rs │ │ ├── binaryish.f.rs │ │ ├── blocks.f.rs │ │ ├── chain.f.rs │ │ ├── closure.f.rs │ │ ├── dangling.f.rs │ │ ├── file.f.rs │ │ ├── flow.f.rs │ │ ├── functions.f.rs │ │ ├── ignore.attr.f.rs │ │ ├── ignore.f.rs │ │ ├── ignore.file.f.rs │ │ ├── imports.f.rs │ │ ├── macro.f.rs │ │ ├── multiple.f.rs │ │ ├── parens.f.rs │ │ └── whitespace.f.rs │ ├── common │ │ ├── arrays.f.rs │ │ ├── assignments.f.rs │ │ ├── binaryish.f.rs │ │ ├── chains.f.rs │ │ ├── chains.first-argument-expansion.f.rs │ │ ├── chains.last-argument-expansion.f.rs │ │ ├── closures.f.rs │ │ ├── destructuring.f.rs │ │ ├── members.f.rs │ │ └── types.f.rs │ ├── issues │ │ ├── 21 │ │ │ ├── fn_comment.f.rs │ │ │ ├── fn_fn.f.rs │ │ │ ├── fn_ln.f.rs │ │ │ ├── ln_fn_ln.f.rs │ │ │ └── mod.f.rs │ │ ├── 0.f.rs │ │ ├── 14.f.rs │ │ ├── 22.f.rs │ │ ├── 25.f.rs │ │ ├── nth-pass.f.1.rs │ │ └── nth-pass.f.rs │ ├── macros │ │ ├── cfg_if.f.rs │ │ ├── if_chain.f.rs │ │ └── matches.f.rs │ └── styling │ │ ├── blockify.f.rs │ │ ├── canInlineBlockBody.f.rs │ │ ├── needsParens.f.rs │ │ └── needsSemi.f.rs ├── print.ts ├── samples │ ├── comments │ │ ├── assignment.rs │ │ ├── binaryish.rs │ │ ├── blocks.rs │ │ ├── chain.rs │ │ ├── closure.rs │ │ ├── dangling.rs │ │ ├── file.rs │ │ ├── flow.rs │ │ ├── functions.rs │ │ ├── ignore.attr.rs │ │ ├── ignore.file.rs │ │ ├── ignore.rs │ │ ├── imports.rs │ │ ├── macro.rs │ │ ├── multiple.rs │ │ ├── parens.rs │ │ └── whitespace.rs │ ├── common │ │ ├── arrays.rs │ │ ├── assignments.rs │ │ ├── binaryish.rs │ │ ├── chains.first-argument-expansion.rs │ │ ├── chains.last-argument-expansion.rs │ │ ├── chains.rs │ │ ├── closures.rs │ │ ├── destructuring.rs │ │ ├── members.rs │ │ └── types.rs │ ├── issues │ │ ├── 21 │ │ │ ├── fn_comment.rs │ │ │ ├── fn_fn.rs │ │ │ ├── fn_ln.rs │ │ │ ├── ln_fn_ln.rs │ │ │ └── mod.rs │ │ ├── 0.rs │ │ ├── 14.rs │ │ ├── 22.rs │ │ ├── 25.rs │ │ └── nth-pass.rs │ ├── macros │ │ ├── cfg_if.rs │ │ ├── if_chain.rs │ │ └── matches.rs │ └── styling │ │ ├── blockify.rs │ │ ├── canInlineBlockBody.rs │ │ ├── needsParens.rs │ │ └── needsSemi.rs └── test.build.ts ├── tsconfig.base.json ├── tsconfig.build.json └── tsconfig.json /.github/ISSUE_TEMPLATE/Bug_report.yml: -------------------------------------------------------------------------------- 1 | name: ✨ Formatting 2 | description: Issues for incorrect or unreadable code 3 | body: 4 | - type: textarea 5 | id: code 6 | attributes: 7 | label: Input code 8 | placeholder: Paste the input code here. 9 | render: rust 10 | validations: 11 | required: true 12 | - type: textarea 13 | id: output 14 | attributes: 15 | label: Output code 16 | placeholder: Paste the formatted code here. 17 | render: rust 18 | validations: 19 | required: true 20 | - type: textarea 21 | id: extra 22 | attributes: 23 | label: Additional context 24 | placeholder: Add other relevant context about the problem here. 25 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | contact_links: 2 | - name: Github discussion board 3 | url: https://github.com/jinxdash/prettier-plugin-rust/discussions 4 | about: Questions and answers 5 | 6 | blank_issues_enabled: true 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # npm 2 | node_modules 3 | 4 | # cache 5 | /.rollup.cache/ 6 | *.tsbuildinfo 7 | 8 | # debug 9 | *.temp.* 10 | *.temp/ 11 | 12 | # repl 13 | /repl/ 14 | 15 | # build 16 | /index.* 17 | /extension/index.* 18 | *.vsix 19 | /crate/target -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "ext/jinx-rust"] 2 | path = ext/jinx-rust 3 | url = https://github.com/jinxdash/jinx-rust.git 4 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | link-workspace-packages = false -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | // A launch configuration that compiles the extension and then opens it inside a new window 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | { 6 | "version": "0.2.0", 7 | "configurations": [ 8 | { 9 | "args": ["--extensionDevelopmentPath=${workspaceFolder}/extension"], 10 | "name": "Launch Extension", 11 | "outFiles": ["${workspaceFolder}/extension/index.js"], 12 | "request": "launch", 13 | "type": "extensionHost" 14 | } 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "npm.exclude": [ 3 | "**/ext/jinx-rust" 4 | ], 5 | "files.exclude": { 6 | "ext": true 7 | } 8 | } -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Prettier Rust Changelog 2 | 3 | ## Unreleased 4 | 5 | - fix: clear some issues related to formatting `#[attr]` like full-on expressions ([#25](jinxdash/prettier-plugin-rust/issues/25)) 6 | 7 | ## 0.1.9 8 | 9 | - feat: format `cfg_if!` macros 10 | - feat: format `@` character in `macro_rules` 11 | - fix: format `.` and `e0` to float instead of int ([#14](https://github.com/jinxdash/prettier-plugin-rust/issues/14), [#16](https://github.com/jinxdash/prettier-plugin-rust/issues/16)) 12 | - fix: always end files with a newline ([#21](https://github.com/jinxdash/prettier-plugin-rust/issues/21)) 13 | - fix: avoid removing optional semi in rare [rust compiler bug](https://github.com/rust-lang/rust/issues/70844) ([#22](https://github.com/jinxdash/prettier-plugin-rust/issues/22)) 14 | 15 | ## 0.1.8 16 | 17 | - feat(extension): display message when formatting fails due to non-parser errors. 18 | - feat: move `..spread`, `..` to the end of patterns and reassignments ([#7](https://github.com/jinxdash/prettier-plugin-rust/pull/7)) 19 | - fix: remove comma after `..` in patterns and reassignments ([#7](https://github.com/jinxdash/prettier-plugin-rust/pull/7)) 20 | - fix: support malformed `macro_rules!` ([jinx-rust@0.1.6](/jinxdash/jinx-rust/pull/2)) 21 | - fix: unprinted comment errors in failed macros ([#8](https://github.com/jinxdash/prettier-plugin-rust/pull/8)) 22 | 23 | ## 0.1.7 24 | 25 | - feat: move `..spread` to the end of struct literals ([#6](https://github.com/jinxdash/prettier-plugin-rust/pull/6)) 26 | - fix: remove comma after `..spread` in struct literals ([#6](https://github.com/jinxdash/prettier-plugin-rust/pull/6)) 27 | 28 | ## 0.1.6 29 | 30 | - fix: parenthesize >1 length `dyn`/`impl` types nested in unary types. ([#4](https://github.com/jinxdash/prettier-plugin-rust/pull/4)) 31 | - fix: remove comma after `match` cases with block-like macro expressions. ([#4](https://github.com/jinxdash/prettier-plugin-rust/pull/4)) 32 | 33 | ## 0.1.5 34 | 35 | - feat: wrap non-block closure expressions with a block when a `->` ReturnType is defined 36 | - fix: add extension to filepath in ESM imports ([#2](https://github.com/jinxdash/prettier-plugin-rust/issues/2)) 37 | - fix: add missing whitespace in `let_else` feature 38 | - fix(extension): disable config caching 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022-present jinxdash (https://github.com/jinxdash) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /crate/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "prettier" 7 | version = "0.1.5" 8 | -------------------------------------------------------------------------------- /crate/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "prettier" 3 | version = "0.1.5" 4 | edition = "2021" 5 | readme = "README.md" 6 | license = "MIT" 7 | description = "Opinionated code formatter - `cargo fmt` alternative (Community) (WIP)" 8 | repository = "https://github.com/jinxdash/prettier-plugin-rust" 9 | keywords = ["format", "rustfmt", "tool", "development", "editor"] 10 | categories = ["development-tools", "text-editors", "web-programming"] 11 | 12 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 13 | 14 | [dependencies] 15 | -------------------------------------------------------------------------------- /crate/README.md: -------------------------------------------------------------------------------- 1 | # Prettier crate 2 | 3 | _Reserved_ (August 2022) 4 | 5 | https://github.com/jinxdash/prettier-plugin-rust 6 | 7 | - _(todo) Crate provides Prettier CLI_ 8 | - _(todo) Rust binding for `prettier.format`_ 9 | - _(todo) Configuration and version-control of prettier and its plugins from `Cargo.toml`_ -------------------------------------------------------------------------------- /crate/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | println!("Hello, world!"); 3 | } 4 | -------------------------------------------------------------------------------- /extension/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022-present jinxdash (https://github.com/jinxdash) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /extension/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinxdash/prettier-plugin-rust/61dc16d002ba984ed7c69d2ffc8b6999065a7408/extension/icon.png -------------------------------------------------------------------------------- /extension/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "icon": "icon.png", 3 | "name": "prettier-rust", 4 | "publisher": "jinxdash", 5 | "displayName": "Prettier - Code formatter (Rust)", 6 | "description": "Prettier Rust is a code formatter that autocorrects bad syntax", 7 | "repository": { 8 | "type": "git", 9 | "url": "https://github.com/jinxdash/prettier-plugin-rust.git", 10 | "directory": "extension" 11 | }, 12 | "author": "jinxdash (https://github.com/jinxdash)", 13 | "version": "0.1.9", 14 | "engines": { 15 | "vscode": "^1.69.0" 16 | }, 17 | "categories": [ 18 | "Formatters" 19 | ], 20 | "keywords": [ 21 | "rust", 22 | "formatter", 23 | "prettier" 24 | ], 25 | "scripts": { 26 | "bundle": "esbuild src/index.ts --bundle --outfile=index.js --format=cjs --platform=node --external:vscode", 27 | "watch": "pnpm run bundle --watch", 28 | "package": "pnpm run bundle && pnpm vsce package --no-dependencies", 29 | "publish": "pnpm vsce publish --no-dependencies" 30 | }, 31 | "contributes": { 32 | "languages": [ 33 | { 34 | "id": "rust", 35 | "aliases": [ 36 | "rs" 37 | ], 38 | "extensions": [ 39 | "rs" 40 | ] 41 | } 42 | ] 43 | }, 44 | "devDependencies": { 45 | "@types/node": "^18.0.6", 46 | "@types/vscode": "^1.69.0", 47 | "esbuild": "^0.14.49", 48 | "typescript": "^4.7.4" 49 | }, 50 | "dependencies": { 51 | "prettier": "^2.7.1", 52 | "jinx-rust": "0.1.6", 53 | "prettier-plugin-rust": "workspace:prettier-plugin-rust" 54 | }, 55 | "main": "index.js", 56 | "activationEvents": [ 57 | "onStartupFinished" 58 | ] 59 | } 60 | -------------------------------------------------------------------------------- /extension/src/index.ts: -------------------------------------------------------------------------------- 1 | import { rs } from "jinx-rust"; 2 | import path from "node:path"; 3 | import prettier, { Config, resolveConfig } from "prettier"; 4 | import plugin from "prettier-plugin-rust"; 5 | import { ExtensionContext, languages, Position, Range, TextDocument, TextEdit, window } from "vscode"; 6 | 7 | const console = createOutputChannel("Prettier (Rust)"); 8 | 9 | console.log(`VSCode Extension: ${process.env.EXTENSION_NAME || "jinxdash.prettier-rust"}@${process.env.EXTENSION_VERSION || "dev"}`); 10 | export async function activate(context: ExtensionContext) { 11 | context.subscriptions.push( 12 | languages.registerDocumentFormattingEditProvider("rust", { 13 | async provideDocumentFormattingEdits(document) { 14 | const config: Config = { 15 | filepath: cmd(document.fileName), 16 | ...((await resolveConfig(document.fileName, { editorconfig: true, useCache: false })) ?? {}), 17 | }; 18 | console.log("", `# Formatting using prettier@${prettier.version}`, { 19 | ...config, 20 | plugins: config.plugins?.flatMap((p) => (typeof p === "string" ? p : p.printers && Object.keys(p.printers))), 21 | }); 22 | if ( 23 | !config.plugins?.some((plugin) => typeof plugin === "object" && plugin.languages?.some((lang) => lang.name === "Rust")) 24 | ) { 25 | config.parser = "jinx-rust"; 26 | config.plugins ??= [plugin]; 27 | } 28 | return format(document, config); 29 | }, 30 | }) 31 | ); 32 | } 33 | 34 | function format(document: TextDocument, config: Config) { 35 | // length of common prefix 36 | const next = tryFormat(document, config); 37 | const prev = document.getText(); 38 | if (prev === next) { 39 | // console.log("No changes"); 40 | return []; 41 | } 42 | const end = Math.min(prev.length, next.length); 43 | var i = 0; 44 | var j = 0; 45 | for (var i = 0; i < end && compare(i, i); ++i); 46 | for (var j = 0; i + j < end && compare(prev.length - j - 1, next.length - j - 1); ++j); 47 | // console.log([i, j]); 48 | return [TextEdit.replace(new Range(document.positionAt(i), document.positionAt(prev.length - j)), next.substring(i, next.length - j))]; 49 | function compare(i: number, j: number) { 50 | return prev.charCodeAt(i) === next.charCodeAt(j); 51 | } 52 | } 53 | 54 | function tryFormat(doc: TextDocument, config: prettier.Config) { 55 | try { 56 | return prettier.format(doc.getText(), config); 57 | } catch (e) { 58 | if ((e as any).loc) { 59 | try { 60 | rs.parseFile(doc.getText(), { filepath: config.filepath }); 61 | } catch (_e) { 62 | const e2 = _e as rs.ParserError; 63 | const pos = new Position(e2.loc.start.line - 1, e2.loc.start.column - 1); 64 | window.showTextDocument(doc, { selection: new Range(pos, pos) }); 65 | window.showErrorMessage(e2.message); 66 | } 67 | } else { 68 | console.log(e); 69 | window.showErrorMessage((e as any).message); 70 | } 71 | return doc.getText(); 72 | } 73 | } 74 | 75 | function createOutputChannel(name: string) { 76 | const out = window.createOutputChannel(name); 77 | return { 78 | log(...arr: any[]) { 79 | for (var item of arr) { 80 | if (typeof item === "string") { 81 | out.appendLine(unstyle(item)); 82 | } else if (item instanceof Error) { 83 | if (item?.message) out.appendLine(unstyle(item.message)); 84 | if (item?.stack) out.appendLine(unstyle(item.stack)); 85 | } else { 86 | out.appendLine(JSON.stringify(item, null, 2)); 87 | } 88 | } 89 | }, 90 | }; 91 | } 92 | function unstyle(str: string) { 93 | return str.replace(/\x1B\[[0-9][0-9]?m/g, ""); 94 | } 95 | 96 | function cmd(filepath: string | undefined, frompath = "") { 97 | return normPath(path.relative(frompath, normPath(filepath ?? ""))) || "."; 98 | } 99 | function normPath(filepath: string) { 100 | return filepath.replace(/^file:\/\/\//, "").replace(/\\\\?/g, "/"); 101 | } 102 | -------------------------------------------------------------------------------- /extension/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.base.json", 3 | "compilerOptions": { "rootDir": "src" }, 4 | "include": ["src"] 5 | } 6 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "prettier-plugin-rust", 3 | "version": "0.1.9", 4 | "description": "Prettier plugin for Rust", 5 | "repository": { 6 | "type": "git", 7 | "url": "https://github.com/jinxdash/prettier-plugin-rust.git" 8 | }, 9 | "author": "jinxdash (https://github.com/jinxdash)", 10 | "keywords": [ 11 | "prettier", 12 | "formatter", 13 | "rust" 14 | ], 15 | "license": "MIT", 16 | "type": "module", 17 | "main": "index.cjs", 18 | "module": "index.js", 19 | "types": "index.d.ts", 20 | "exports": { 21 | "./package.json": "./package.json", 22 | ".": { 23 | "require": "./index.cjs", 24 | "import": "./index.js" 25 | } 26 | }, 27 | "files": [ 28 | "index.js", 29 | "index.cjs", 30 | "index.d.ts", 31 | "package.json", 32 | "LICENSE" 33 | ], 34 | "scripts": { 35 | "build": "ts-node ./scripts/build.ts && ts-node ./tests/test.build.ts", 36 | "test-build": "ts-node ./tests/test.build.ts", 37 | "test-print-samples": "ts-node ./tests/print.ts", 38 | "dev-repl": "ts-node ./scripts/dev.repl.ts", 39 | "dev-format-local": "ts-node ./scripts/dev.format.ts" 40 | }, 41 | "devDependencies": { 42 | "@swc/core": "^1.2.248", 43 | "@types/node": "^18.0.6", 44 | "@types/prettier": "^2.7.0", 45 | "ts-node": "^10.9.1", 46 | "tsup": "^6.2.3", 47 | "typescript": "^4.8.2" 48 | }, 49 | "dependencies": { 50 | "jinx-rust": "0.1.6", 51 | "prettier": "^2.7.1" 52 | }, 53 | "prettier": { 54 | "printWidth": 140, 55 | "semi": true, 56 | "tabWidth": 4, 57 | "useTabs": true, 58 | "endOfLine": "lf", 59 | "overrides": [ 60 | { 61 | "files": [ 62 | "**/*.md" 63 | ], 64 | "options": { 65 | "printWidth": 80, 66 | "useTabs": false, 67 | "tabWidth": 2 68 | } 69 | } 70 | ] 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /pnpm-workspace.yaml: -------------------------------------------------------------------------------- 1 | packages: 2 | - 'ext/*' 3 | - 'extension' -------------------------------------------------------------------------------- /scripts/build.ts: -------------------------------------------------------------------------------- 1 | import { build } from "tsup"; 2 | import { createStripPlugin } from "../ext/jinx-rust/scripts/utils/build"; 3 | 4 | await build({ 5 | dts: true, 6 | tsconfig: "tsconfig.build.json", 7 | entry: ["src/index.ts"], 8 | external: ["jinx-rust"], 9 | outDir: ".", 10 | format: ["cjs", "esm"], 11 | plugins: [createStripPlugin({ labels: ["__DEV__"], functionCalls: ["devonly"] })], 12 | treeshake: { 13 | preset: "smallest", 14 | moduleSideEffects: false, 15 | propertyReadSideEffects: false, 16 | tryCatchDeoptimization: false, 17 | unknownGlobalSideEffects: false, 18 | }, 19 | }); 20 | -------------------------------------------------------------------------------- /scripts/dev.format.ts: -------------------------------------------------------------------------------- 1 | import prettier from "prettier"; 2 | import { for_each_rs_file } from "../ext/jinx-rust/scripts/utils/common"; 3 | import { update_file } from "../ext/jinx-rust/scripts/utils/fs"; 4 | import { plugin } from "../src/format/plugin"; 5 | 6 | function format(code: string, filepath: string) { 7 | const next = prettier.format(code, { 8 | parser: "jinx-rust", 9 | plugins: [plugin], 10 | printWidth: 100, 11 | tabWidth: 4, 12 | filepath, 13 | }); 14 | if (code !== next && code.trim() !== next.trim()) { 15 | update_file(filepath, next, { external: true }); 16 | } 17 | } 18 | 19 | globalThis.TESTS_FORMAT_DEV = true; 20 | 21 | for_each_rs_file( 22 | [`E:/dev/github/rust/rust-lang/`], 23 | (file) => { 24 | format(file.content, file.cmd); 25 | }, 26 | ["test", "tests"] 27 | ).then(() => { 28 | globalThis.TESTS_FORMAT_DEV = false; 29 | }); 30 | -------------------------------------------------------------------------------- /scripts/dev.repl.ts: -------------------------------------------------------------------------------- 1 | import { createASTtoJSONPrinter, createPrettierPrinter, rs_createREPL } from "../ext/jinx-rust/scripts/utils"; 2 | import { plugin } from "../src/format/plugin"; 3 | 4 | rs_createREPL([ 5 | createPrettierPrinter( 6 | { 7 | parser: "jinx-rust", 8 | plugins: [plugin], 9 | }, 10 | true 11 | ), 12 | createASTtoJSONPrinter(), 13 | ]); 14 | -------------------------------------------------------------------------------- /scripts/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.base.json", 3 | "include": ["../tests", "../scripts"], 4 | "references": [{ "path": "../tsconfig.json" }, { "path": "../ext/jinx-rust/scripts/tsconfig.json" }], 5 | "compilerOptions": { 6 | "rootDir": ".." 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/format/external.ts: -------------------------------------------------------------------------------- 1 | import { Attribute, AttributeOrDocComment, Comment, DocCommentAttribute, LocArray, MemberExpression, Node, SourceFile } from "jinx-rust"; 2 | import { PickProps } from "jinx-rust/utils"; 3 | import type { Doc, ParserOptions, Printer } from "prettier"; 4 | import doc from "prettier/doc.js"; 5 | import { AssertTypesEq } from "../utils/common"; 6 | 7 | export type { Doc, ParserOptions, Plugin, Printer } from "prettier"; 8 | 9 | declare module "prettier/doc.js" { 10 | namespace utils { 11 | function canBreak(doc: Doc): boolean; 12 | } 13 | } 14 | 15 | export const { 16 | join, 17 | line, 18 | softline, 19 | hardline, 20 | literalline, 21 | group, 22 | conditionalGroup, 23 | fill, 24 | lineSuffix, 25 | lineSuffixBoundary, 26 | cursor, 27 | breakParent, 28 | ifBreak, 29 | trim, 30 | indent, 31 | indentIfBreak, 32 | align, 33 | addAlignmentToDoc, 34 | markAsRoot, 35 | dedentToRoot, 36 | dedent, 37 | hardlineWithoutBreakParent, 38 | literallineWithoutBreakParent, 39 | label, 40 | } = doc.builders; 41 | 42 | export const { 43 | isConcat, 44 | getDocParts, 45 | willBreak, 46 | traverseDoc, 47 | findInDoc, 48 | mapDoc, 49 | propagateBreaks, 50 | removeLines, 51 | stripTrailingHardline, 52 | normalizeParts, 53 | normalizeDoc, 54 | cleanDoc, 55 | canBreak, 56 | } = doc.utils; 57 | 58 | export const Symbol_comments = Symbol.for("comments"); 59 | 60 | export interface CustomOptions extends ParserOptions { 61 | [Symbol_comments]: AnyComment[]; 62 | rsParsedFile: SourceFile; 63 | commentSpans: Map; 64 | printer: Printer; 65 | cursorNode: any; 66 | 67 | comments: Comment[]; 68 | danglingAttributes: AttributeOrDocComment[]; 69 | actuallyMethodNodes: WeakSet; 70 | } 71 | 72 | export type NodeWithComments = T & { comments: AnyComment[] }; 73 | export interface MutatedComment extends Comment, PrettierCommentInfo {} 74 | export interface MutatedAttribute extends Attribute, PrettierCommentInfo {} 75 | export interface MutatedDocComment extends DocCommentAttribute, PrettierCommentInfo {} 76 | export type AnyComment = MutatedComment | MutatedAttribute | MutatedDocComment; 77 | 78 | type keyofDelimitedArrayProps = T extends never ? never : keyof PickProps">>; 79 | 80 | __DEV__: AssertTypesEq>(); 81 | 82 | export enum DCM { 83 | "arguments" = "arguments", 84 | "parameters" = "parameters", 85 | "items" = "items", 86 | "properties" = "properties", 87 | "members" = "members", 88 | "body" = "body", 89 | "cases" = "cases", 90 | "typeArguments" = "typeArguments", 91 | "ltParameters" = "ltParameters", 92 | "generics" = "generics", 93 | "specifiers" = "specifiers", 94 | "rules" = "rules", 95 | "match" = "match", 96 | "transform" = "transform", 97 | "segments" = "segments", 98 | } 99 | 100 | export interface PrettierCommentInfo { 101 | trailing: boolean; 102 | leading: boolean; 103 | unignore: boolean; 104 | printed: boolean; 105 | placement: "ownLine" | "endOfLine" | "remaining"; 106 | // nodeDescription?: any; 107 | marker?: DCM; 108 | } 109 | 110 | export interface AstPath { 111 | stack: (Node | string | number)[]; 112 | callParent(callback: (path: this) => R, count?: number): R; 113 | getName(): PropertyKey | null; 114 | getValue(): T; 115 | getNode(count?: number): T | null; 116 | getParentNode(count?: number): T | null; 117 | 118 | match(...predicates: ((node: Node, name: string | null, number: number | null) => boolean)[]): boolean; 119 | 120 | call(callback: (path: AstPath, index: number, value: any) => R, ...props: (string | number)[]): R; 121 | each(callback: (path: AstPath, index: number, value: any) => void, ...props: (string | number)[]): void; 122 | map(callback: (path: AstPath, index: number, value: any) => R, ...props: (string | number)[]): R[]; 123 | } 124 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import { plugin } from "./format/plugin"; 2 | 3 | export default plugin; 4 | export const languages = plugin.languages; 5 | export const parsers = plugin.parsers; 6 | export const printers = plugin.printers; 7 | export const options = plugin.options; 8 | export const defaultOptions = plugin.defaultOptions; 9 | -------------------------------------------------------------------------------- /src/transform/custom/attribute.ts: -------------------------------------------------------------------------------- 1 | import { 2 | AttrSegment, 3 | CallExpression, 4 | DelimKind, 5 | ExpressionPath, 6 | Identifier, 7 | Literal, 8 | LocArray, 9 | MacroInvocation, 10 | NodeType, 11 | PunctuationToken, 12 | ReassignmentExpression, 13 | TK, 14 | rs, 15 | } from "jinx-rust"; 16 | import { isTK, start } from "jinx-rust/utils"; 17 | import { assert, exit } from "../../utils/common"; 18 | import { isIdent } from "./utils"; 19 | 20 | type SimpleAttrItem = 21 | | Identifier // 22 | | Literal 23 | | ExpressionPath 24 | | CallExpression 25 | | ReassignmentExpression 26 | | MacroInvocation; 27 | 28 | export function transform_simpleAttrSyntax(segments: MacroInvocation["segments"]) { 29 | assert(segments.length !== 0, segments.loc.url()); 30 | return transform_segments(segments, false); 31 | 32 | function transform_segments( 33 | seq: LocArray, 34 | nestedCall: N 35 | ): N extends true ? LocArray : SimpleAttrItem { 36 | let i = 0; 37 | 38 | if (nestedCall) { 39 | const args = rs.createLocArray(DelimKind["()"], seq.loc.clone()); 40 | while (i !== seq.length) { 41 | args.push(read(true)); 42 | if (i === seq.length) break; 43 | assert(isTK(seq[i++], TK[","])); 44 | } 45 | return args as any; 46 | } else { 47 | const res = read(true); 48 | assert(i === seq.length, res.loc.url()); 49 | return res as any; 50 | } 51 | 52 | function read(allowEq: boolean): SimpleAttrItem { 53 | let lhs: Identifier | ExpressionPath; 54 | 55 | switch (seq[i].nodeType) { 56 | case NodeType.Literal: 57 | return seq[i++] as Literal; 58 | case NodeType.Identifier: 59 | lhs = seq[i++] as Identifier; 60 | break; 61 | case NodeType.PunctuationToken: 62 | assert((seq[i] as PunctuationToken).tk === TK["::"], seq[i].loc.url()); 63 | lhs = eatPathSegment(undefined); 64 | break; 65 | default: 66 | exit.never(); 67 | } 68 | 69 | while (true) { 70 | if (i === seq.length) return lhs; 71 | const seg = seq[i]; 72 | switch (seg.nodeType) { 73 | case NodeType.PunctuationToken: 74 | switch (seg.tk) { 75 | case TK[","]: 76 | assert(nestedCall); 77 | return lhs; 78 | case TK["="]: { 79 | assert(allowEq); 80 | const right = (i++, read(false)); 81 | return rs.mockNode(NodeType.ReassignmentExpression, right.loc.cloneFrom(start(lhs)), { 82 | tk: TK["="], 83 | kind: DelimKind["="], 84 | left: lhs, 85 | right, 86 | }); 87 | } 88 | case TK["::"]: 89 | lhs = eatPathSegment(lhs); 90 | continue; 91 | default: 92 | exit.never(); 93 | } 94 | case NodeType.DelimGroup: 95 | assert(seg.segments.dk === DelimKind["()"]); 96 | return rs.mockNode(NodeType.CallExpression, seq[i++].loc.cloneFrom(start(lhs)), { 97 | callee: lhs, 98 | typeArguments: undefined, 99 | method: undefined, 100 | arguments: transform_segments(seg.segments, true), 101 | }); 102 | default: 103 | exit.never(); 104 | } 105 | } 106 | } 107 | 108 | function eatPathSegment(left: undefined | Identifier | ExpressionPath) { 109 | const segment = seq[i + 1]; 110 | assert(isIdent(segment)); 111 | const res = rs.mockNode(NodeType.ExpressionPath, segment.loc.cloneFrom(start(left ?? seq[i])), { namespace: left, segment }); 112 | i += 2; 113 | return res; 114 | } 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /src/transform/custom/cfg_if.ts: -------------------------------------------------------------------------------- 1 | import { 2 | DelimGroup, 3 | DelimKind, 4 | IfBlockExpression, 5 | LocArray, 6 | MacroInvocation, 7 | NodeType, 8 | NodeWithBody, 9 | rs, 10 | Segment, 11 | Snippet, 12 | StatementNode, 13 | TK, 14 | } from "jinx-rust"; 15 | import { insertNodes, start, transferAttributes } from "jinx-rust/utils"; 16 | import { assert, iLast } from "../../utils/common"; 17 | import { isGroup, isIdent, isToken } from "./utils"; 18 | 19 | export function transform_macro_cfg_if(segments: MacroInvocation["segments"]) { 20 | const danglingAttributes: Snippet["danglingAttributes"] = []; 21 | const comments: Snippet["comments"] = []; 22 | 23 | const block = (function create_if_block(i: number): IfBlockExpression | undefined { 24 | if (i >= segments.length) return undefined; 25 | 26 | const _if = segments[i]; 27 | const pound = segments[i + 1]; 28 | const grp = segments[i + 2]; 29 | const block = segments[i + 3]; 30 | const _else = segments[i + 4]; 31 | 32 | assert( 33 | isIdent(_if, "if") && 34 | isToken(pound, TK["#"]) && 35 | isGroup(grp, DelimKind["[]"]) && 36 | isGroup(block, DelimKind["{}"]) && 37 | (!_else || isIdent(_else, "else")) 38 | ); 39 | 40 | return create_block(block, (body) => 41 | rs.mockNode(NodeType.IfBlockExpression, block.loc.cloneFrom(start(_if)), { 42 | label: undefined, 43 | condition: rs.mockNode(NodeType.Attribute, grp.loc.cloneFrom(start(pound)), { 44 | segments: grp.segments, 45 | value: grp.segments.loc.sliceText(), 46 | line: false, 47 | inner: false, 48 | }) as any, 49 | body: body, 50 | else: (_else && iLast(i + 5, segments) 51 | ? function create_else_block(i: number) { 52 | const block = segments[i]; 53 | assert(isGroup(block, DelimKind["{}"])); 54 | return create_block(block, (body) => 55 | rs.mockNode(NodeType.BlockExpression, body.loc.clone(), { 56 | label: undefined, 57 | body, 58 | }) 59 | ); 60 | } 61 | : create_if_block)(i + 5), 62 | }) 63 | ); 64 | })(0); 65 | 66 | const ast = rs.createLocArray( 67 | segments.dk, 68 | segments.loc, 69 | block && [ 70 | rs.mockNode(NodeType.ExpressionStatement, block.loc.clone(), { 71 | expression: block, 72 | semi: false, 73 | }), 74 | ] 75 | ); 76 | 77 | return rs.mockNode(NodeType.Snippet, segments.loc.clone(), { ast, danglingAttributes, comments }); 78 | 79 | function create_block( 80 | group: DelimGroup & { segments: { dk: 3 } }, 81 | fn: (statements: LocArray) => R 82 | ): R { 83 | const snippet = rs.toBlockBody(group.segments); 84 | 85 | insertNodes(danglingAttributes, snippet.danglingAttributes); 86 | insertNodes(comments, snippet.comments); 87 | 88 | const block = fn(snippet.ast); 89 | transferAttributes(snippet, block); 90 | return block; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/transform/custom/utils.ts: -------------------------------------------------------------------------------- 1 | import { DelimGroup, DelimKind, Identifier, LocArray, PunctuationToken, Segment, TK } from "jinx-rust"; 2 | import { isTK, is_DelimGroup, is_Identifier, is_PunctuationToken } from "jinx-rust/utils"; 3 | 4 | export function isIdent(node: Segment | undefined, name?: string): node is Identifier { 5 | return !!node && is_Identifier(node) && (null == name || node.name === name); 6 | } 7 | export function isToken(node: Segment | undefined, tk?: TK): node is PunctuationToken { 8 | return !!node && (null == tk ? is_PunctuationToken(node) : isTK(node, tk)); 9 | } 10 | export function isGroup(node: Segment | undefined, dk?: D): node is DelimGroup & { segments: LocArray } { 11 | return !!node && is_DelimGroup(node) && (null == dk || node.segments.dk === dk); 12 | } 13 | 14 | export function isCallLike(tk_1: Segment | undefined, tk_2: Segment | undefined): boolean { 15 | return !!tk_1 && !!tk_2 && is_Identifier(tk_1) && is_DelimGroup(tk_2) && tk_2.segments.dk === DelimKind["()"]; 16 | } 17 | -------------------------------------------------------------------------------- /src/utils/debug.ts: -------------------------------------------------------------------------------- 1 | import { clamp, color, getTerminalWidth, normPath } from "./common"; 2 | 3 | const cwd = // @ts-expect-error 4 | typeof process === "object" && typeof process?.cwd === "function" ? /* @__PURE__ */ normPath(/* @__PURE__ */ process.cwd() ?? "") : ""; 5 | function normPath_strip_cwd(filepath: string) { 6 | let normFilePath = normPath(filepath); 7 | return normFilePath.startsWith(cwd) ? normFilePath.slice(cwd.length + 1) : normFilePath; 8 | } 9 | 10 | type StackStyleFn = (callee: string, item: StackItem) => (str: string) => string; 11 | interface Stack extends Array { 12 | message: string; 13 | style?: { callee?: StackStyleFn; url?: StackStyleFn } | undefined; 14 | } 15 | 16 | class StackLine { 17 | declare readonly raw: string; 18 | declare readonly callee: string; 19 | declare readonly filepath: string; 20 | declare readonly line: string; 21 | declare readonly col: string; 22 | declare readonly other: string; 23 | declare readonly url: string; 24 | constructor(raw: string) { 25 | ({ 26 | 1: this.callee = "", 27 | 2: this.filepath = "", 28 | 3: this.line = "", 29 | 4: this.col = "", 30 | 5: this.other = "", 31 | } = (this.raw = raw).match(/at (?:(.+?)\s+\()?(?:(.+?):([0-9]+)(?::([0-9]+))?|([^)]+))\)?/) ?? ["", "", "", "", "", ""]); 32 | this.url = this.filepath // 33 | ? normPath_strip_cwd(this.filepath) + (this.line && this.col && `:${this.line}:${this.col}`) 34 | : this.other === "native" 35 | ? "" 36 | : ""; 37 | } 38 | } 39 | 40 | function getPrintWidth() { 41 | return clamp(0, getTerminalWidth(128), 200) - 4; 42 | } 43 | 44 | class StackItem extends StackLine { 45 | constructor(private readonly stack: Stack, readonly i: number, raw: string) { 46 | super(raw); 47 | } 48 | hidden = false; 49 | hide() { 50 | this.hidden = true; 51 | return this; 52 | } 53 | hideNext(n: number) { 54 | for (let i = 0; i < n; i++) this.at(i)?.hide(); 55 | } 56 | hideWhileTrue(test: (line: StackItem) => boolean) { 57 | let line: StackItem | undefined = this; 58 | while (line && test(line)) line = line.hide().next(); 59 | } 60 | at(relIndex: number) { 61 | return this.i + relIndex >= this.stack.length || this.i + relIndex < 0 ? undefined : this.stack[this.i + relIndex]; 62 | } 63 | next() { 64 | return this.at(+1); 65 | } 66 | toString() { 67 | const url = this.url; 68 | const calleeColor = this.stack.style?.callee?.(this.callee, this) ?? color.cyan; 69 | const urlColor = this.stack.style?.url?.(url, this) ?? color.grey; 70 | return compose2Cols(" at " + calleeColor(this.callee), urlColor(url), getPrintWidth()); 71 | } 72 | } 73 | 74 | // prettier-ignore 75 | function createStack(message: string, Error_stack: string, style: Stack["style"]): Stack { 76 | for (var STACK: Stack = [] as any, i = 0, stack = Error_stack.split("\n").slice(2); i < stack.length; i++) STACK[i] = new StackItem(STACK, i, stack[i]); 77 | return (STACK.message = message), (STACK.style = style), STACK; 78 | } 79 | 80 | function composeStack(stack: Stack) { 81 | var hidden = 0; 82 | var str = stack.message; 83 | for (var item of stack) item.hidden ? ++hidden : (str += "\n" + item.toString()); 84 | return str + (hidden > 0 ? "\n" + color.grey(compose2Cols("", `...filtered ${hidden} lines`, getPrintWidth())) : ""); 85 | } 86 | 87 | export function get_caller_cmd(offset = 0) { 88 | const obj: { stack: string } = {} as any; 89 | Error.captureStackTrace(obj, get_caller_cmd); 90 | const lines = obj.stack.split("\n"); 91 | return new StackLine(lines[1 + clamp(0, lines.length - 2, offset)]).url; 92 | } 93 | 94 | var Error_prepareStackTrace; 95 | let replaced_default_prepareStackTrace = false; 96 | function custom_prepareStackTrace(err, calls) { 97 | return (Error_prepareStackTrace?.(err, calls) ?? calls.join("\n"))?.replace(/file:\/\/\//g, "").replace(/\\\\?/g, "/") ?? calls; 98 | } 99 | 100 | export function overrideDefaultError(silent = false) { 101 | if (replaced_default_prepareStackTrace === (replaced_default_prepareStackTrace = true)) return; 102 | Error_prepareStackTrace = Error.prepareStackTrace ?? ((_, calls) => calls.join("\n")); 103 | Error.prepareStackTrace = custom_prepareStackTrace; 104 | if (!silent) console.log(color.grey(`[devtools] Replaced Error.prepareStackTrace at ${get_caller_cmd(1)}`)); 105 | } 106 | 107 | export function createCustomError({ 108 | message = "Unknown Error", 109 | editStack = (stack: StackItem[]) => {}, 110 | style = undefined as Stack["style"], 111 | stackTraceLimit = 20, 112 | }): Error { 113 | const _stackTraceLimit = Error.stackTraceLimit; 114 | const _prepareStackTrace = Error.prepareStackTrace; 115 | if (replaced_default_prepareStackTrace && _prepareStackTrace === custom_prepareStackTrace) 116 | Error.prepareStackTrace = Error_prepareStackTrace; 117 | 118 | Error.stackTraceLimit = stackTraceLimit; 119 | 120 | const _ctx: { stack: string } = {} as any; 121 | 122 | Error.captureStackTrace(_ctx, createCustomError); 123 | 124 | const stack = createStack(message, _ctx.stack, style); 125 | Error.prepareStackTrace = function (err, calls) { 126 | editStack(stack); 127 | return composeStack(stack); 128 | }; 129 | 130 | const err = new Error(message); // @ts-expect-error (get) to trigger prepareStackTrace, (set) to prevent treeshaking 131 | err.stack = err.stack; 132 | 133 | Error.stackTraceLimit = _stackTraceLimit; 134 | Error.prepareStackTrace = _prepareStackTrace; 135 | 136 | return err; 137 | } 138 | 139 | function compose2Cols(left: string, right: string, len = 64, min = 1) { 140 | return left + " ".repeat(clamp(min, len, len - (color.unstyledLength(left) + color.unstyledLength(right)))) + right; 141 | } 142 | -------------------------------------------------------------------------------- /tests/output-ext/errors/foo.rs: -------------------------------------------------------------------------------- 1 | > Error.toString() 2 | > 3 | ---------------------------------------------------------------------------------------------------- 4 | -1 5 | 6 | 1 | ~ 7 | ^ Unexpected End Of File, expected Expression 8 | 2 9 | 3 10 | ---------------------------------------------------------------------------------------------------- 11 | ParserError at ext/jinx-rust/tests/samples/errors/foo.rs:1:1 12 | > inspect(Error) 13 | > Unexpected End Of File, expected Expression 14 | at read_expression_lhs ext/jinx-rust/src/parser/read/expressions.ts:851:11 15 | at fn ext/jinx-rust/src/parser/read/expressions.ts:875:13 16 | at ES_withPrecedence ext/jinx-rust/src/parser/state/index.ts:784:14 17 | at ES_withContext ext/jinx-rust/src/parser/state/index.ts:777:14 18 | at read_stmt_expression ext/jinx-rust/src/parser/read/expressions.ts:874:9 19 | at ExpressionStatement.read ext/jinx-rust/src/parser/read/statements.ts:78:22 20 | at READ_NODE ext/jinx-rust/src/parser/state/constructor.ts:259:46 21 | at ExpressionStatement.call ext/jinx-rust/src/parser/state/constructor.ts:245:4 22 | at read_expr_or_macroInvocation_stmt ext/jinx-rust/src/parser/read/statements.ts:85:29 23 | at read_statement ext/jinx-rust/src/parser/read/statements.ts:814:11 24 | at EACH ext/jinx-rust/src/parser/read/statements.ts:821:42 25 | at fn ext/jinx-rust/src/parser/state/index.ts:500:66 26 | at with_outerAttributes ext/jinx-rust/src/parser/state/index.ts:957:9 27 | at with_outerAttributes_fromStatementContext ext/jinx-rust/src/parser/state/index.ts:975:9 28 | at read_group_noDelim ext/jinx-rust/src/parser/state/index.ts:500:18 29 | ...filtered 5 lines { 30 | [stack]: 'Unexpected End Of File, expected Expression\n' + 31 | ' at \x1B[36mread_expression_lhs\x1B[39m \x1B[90mext/jinx-rust/src/parser/read/expressions.ts:851:11\x1B[39m\n' + 32 | ' at \x1B[36mfn\x1B[39m \x1B[90mext/jinx-rust/src/parser/read/expressions.ts:875:13\x1B[39m\n' + 33 | ' at \x1B[36mES_withPrecedence\x1B[39m \x1B[90mext/jinx-rust/src/parser/state/index.ts:784:14\x1B[39m\n' + 34 | ' at \x1B[36mES_withContext\x1B[39m \x1B[90mext/jinx-rust/src/parser/state/index.ts:777:14\x1B[39m\n' + 35 | ' at \x1B[36mread_stmt_expression\x1B[39m \x1B[90mext/jinx-rust/src/parser/read/expressions.ts:874:9\x1B[39m\n' + 36 | ' at \x1B[34mExpressionStatement.read\x1B[39m \x1B[90mext/jinx-rust/src/parser/read/statements.ts:78:22\x1B[39m\n' + 37 | ' at \x1B[36mREAD_NODE\x1B[39m \x1B[90mext/jinx-rust/src/parser/state/constructor.ts:259:46\x1B[39m\n' + 38 | ' at \x1B[36mExpressionStatement.call\x1B[39m \x1B[90mext/jinx-rust/src/parser/state/constructor.ts:245:4\x1B[39m\n' + 39 | ' at \x1B[36mread_expr_or_macroInvocation_stmt\x1B[39m \x1B[90mext/jinx-rust/src/parser/read/statements.ts:85:29\x1B[39m\n' + 40 | ' at \x1B[36mread_statement\x1B[39m \x1B[90mext/jinx-rust/src/parser/read/statements.ts:814:11\x1B[39m\n' + 41 | ' at \x1B[36mEACH\x1B[39m \x1B[90mext/jinx-rust/src/parser/read/statements.ts:821:42\x1B[39m\n' + 42 | ' at \x1B[36mfn\x1B[39m \x1B[90mext/jinx-rust/src/parser/state/index.ts:500:66\x1B[39m\n' + 43 | ' at \x1B[36mwith_outerAttributes\x1B[39m \x1B[90mext/jinx-rust/src/parser/state/index.ts:957:9\x1B[39m\n' + 44 | ' at \x1B[36mwith_outerAttributes_fromStatementContext\x1B[39m \x1B[90mext/jinx-rust/src/parser/state/index.ts:975:9\x1B[39m\n' + 45 | ' at \x1B[36mread_group_noDelim\x1B[39m \x1B[90mext/jinx-rust/src/parser/state/index.ts:500:18\x1B[39m\n' + 46 | '\x1B[90m ...filtered 5 lines\x1B[39m', 47 | [message]: 'Unexpected End Of File, expected Expression', 48 | loc: { url: 'ext/jinx-rust/tests/samples/errors/foo.rs:1:1', start: { line: 1, column: 1 } }, 49 | ctx: [ [length]: 0 ], 50 | toString: [Function (anonymous)] { [length]: 0, [name]: '', [prototype]: { [constructor]: [Circular *1] } }, 51 | parserState: { 52 | nodes: [ 'SourceFile (--1)', 'Program (...parsing)', 'ExpressionStatement (...parsing)', [length]: 3 ], 53 | discarded_nodes: [ [length]: 0 ], 54 | __ctx_Precedence: [ 0, 3, [length]: 2 ], 55 | max_Precedence_depth: 20, 56 | max_ES_ctx_depth: 12, 57 | max_TY_depth: 12, 58 | __es_optional_start: -1, 59 | __ctx_ES_i: 1, 60 | __ctx_ES_PRCD_i: 1, 61 | __ctx_TY_i: 0, 62 | __ctx_MC_i: 0 63 | } 64 | } -------------------------------------------------------------------------------- /tests/output-ext/expressions/block.f.rs: -------------------------------------------------------------------------------- 1 | fn f() { 2 | ({ foo.0 }).0 = 0; 3 | (async {}).await; 4 | async move { 5 | } 6 | ({ a }).0 += { 0 }; 7 | try { 8 | } 9 | match (try {}) { 10 | } 11 | for lhs in &mut self.0 { 12 | *lhs += rhs; 13 | } 14 | for lhs in self.0.iter_mut() { 15 | } 16 | for _ in [1, 2, 3].into_iter() { 17 | } 18 | for elt in self { 19 | r = r + f(*elt); 20 | } 21 | for _ in [1, 2] { 22 | } 23 | for _ in [1.0, 2.0] { 24 | } 25 | if ( 26 | loop { 27 | } 28 | ) { 29 | } 30 | if let 0 = 1 { 31 | } 32 | if a % 5 == 0 { 33 | } 34 | let x: A = if a % 5 == 0 { 35 | }; 36 | let x = if let 0 = 1 { 37 | }; 38 | if let 0 = 1 { 39 | 3; 40 | } 41 | if ( 42 | { 43 | y = Foo { foo: x }; 44 | } 45 | ) { 46 | } 47 | if q == "" { 48 | } 49 | if ('x' as char) < ('y' as char) { 50 | } else { 51 | } 52 | let a = if 1 { 53 | 1 54 | }; 55 | let a = if 1 { 0 } else if 1 { 0 }; 56 | let a = if (if 0 { 0 } else { 0 }) { 57 | 0 58 | } else { 59 | 0 60 | }; 61 | let a = if 0 { 62 | if 0 { 0 } else { 0 } 63 | } else { 64 | 0 65 | }; 66 | let a = if 0 { 0 } else if 0 { 0 } else { 1 }; 67 | let a = if let 0 = (if let 0 = 0 { 0 } else { 0 }) { 0 } else { 0 }; 68 | for x in 0..10 { 69 | (async { Some(x) }).await.unwrap(); 70 | } 71 | for _ in 1.. { 72 | call_forever(); 73 | } 74 | unsafe { 75 | (Foo { b: () }).a; 76 | } 77 | if 1 { 78 | } else if let Some(a) = Some(1) { 79 | } 80 | } 81 | [ 82 | m::Pub { 83 | 0: loop { 84 | }, 85 | }, 86 | 2_usize + 87 | (loop { 88 | }), 89 | [ 90 | (); 91 | &({ 92 | loop { 93 | continue; 94 | } 95 | }) 96 | ], 97 | [ 98 | (); 99 | loop { 100 | break; 101 | } 102 | ], 103 | [ 104 | (); 105 | { 106 | while true { 107 | break; 108 | } 109 | 0 110 | } 111 | ], 112 | [ 113 | (); 114 | { 115 | for _ in 0usize.. { 116 | } 117 | 0 118 | } 119 | ], 120 | unsafe { *&raw mut y }, 121 | ]; 122 | 123 | a::b(async move { 124 | if let Err(e) = c(d).await { 125 | f!("g: {}", h); 126 | } 127 | }); 128 | 129 | // source: "../../../ext/jinx-rust/tests/samples/expressions/block.rs" -------------------------------------------------------------------------------- /tests/output-ext/expressions/closure.f.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let lam = |(a, ref b, c, ref mut d): (X, X, X, X)| {}; 3 | let x = |_: ()| (); 4 | let y = || x(()); 5 | let mut x = |_: ()| { 6 | outer = 4; 7 | () 8 | }; 9 | let x = move |_: ()| { 10 | let inner = outer; 11 | () 12 | }; 13 | const VTABLE: &'static VTable = &(VTable { 14 | _to_dst_ptr: |_: *mut ()| unsafe { std::mem::zeroed() }, 15 | }); 16 | let z = a(&mut (|x| x - 22)); 17 | let mut unboxed = || {}; 18 | Box::new(move |y| { x + y }); 19 | s( 20 | |f| (*f)(), 21 | Box::new(|| {}) 22 | ); 23 | (0..42).e(|_x| { 24 | match E(()) as R<(), _> { 25 | O(()) => s.push(()), 26 | E(_) => (), 27 | } 28 | }); 29 | <()>::a(|| ()); 30 | let f: &mut dyn FnMut<(_,), E = ()> = &mut (|_: <() as Lt<'_>>::T| {}); 31 | Box::new(move |v| { 32 | (|_| e.d()())(v); 33 | X 34 | }) as Box Q>; 35 | let _c = || { 36 | match b.0.c(1) as D<(), _> { 37 | _ => 0, 38 | } 39 | }; 40 | let f: &dyn Fn(i32) -> _ = &(|x| x + x); 41 | let f = |x: u32| -> u32 { 1 }; 42 | for f in &[d, g, |x| x] { 43 | a!("{}", f(6)); 44 | } 45 | (|| { 46 | (|| { c.d })(); 47 | (move || { a.b })(); 48 | })(); 49 | let q = a.e(async move { b(move || async move { d!() }) }); 50 | let g = { 51 | || z(i) 52 | }; 53 | let _ = || a.e(async { r }); 54 | let _ = E(0) 55 | .d() 56 | .q(|ref _a| true); 57 | let _ = !(4..5).a(|x| (x == 1 || x == 3 || x == 5)); 58 | let _ = !(1..3).a(|x| [1, 2, 3].b(&x)); 59 | let _ = !(1..3).a(|x| (x == 0 || [1, 2, 3].b(&x))); 60 | let _ = !(1..3).a(|x| ([1, 2, 3].b(&x) || x == 0)); 61 | let _ = !(1..3).a( 62 | |x| ([1, 2, 3].b(&x) || x == 0 || [4, 5, 6].c(&x) || x == -1) 63 | ); 64 | let hash: &Fn(&&Block) -> u64 = &(|block| -> u64 { 1 }); 65 | if 66 | outer_guard.map_or( 67 | true, 68 | |(Guard::If(e) | Guard::IfLet(_, e))| !is_local_used(cx, *e, binding_id) 69 | ) 70 | { 71 | } 72 | a = || b; 73 | [ 74 | foo(|| ()), 75 | |x: u32| x + 1, 76 | (|| Box::new(|| {}) as Box)(), 77 | |_: T| 3, 78 | move |x: isize, y| x + y + z, 79 | &mut (|| 22), 80 | &(|| 22), 81 | || { 82 | x += 1; 83 | }, 84 | call(&(|| {}), ()), 85 | <()>::drive(|| ()), 86 | h2(|_: (), _: (), _: (), _: ()| {}), 87 | move |a: isize, b| { a + b }, 88 | move |a: isize, b| { 89 | z; 90 | zz; 91 | a + b 92 | }, 93 | |x: usize| x * 2, 94 | |x: usize| ({ x }) * 2, 95 | |x: usize| ({ x })(), 96 | |x| lib::d!(x), 97 | |x| { 98 | match x { 99 | a => { g(a) } 100 | } 101 | }, 102 | |x| d!(x), 103 | |_| async { () }, 104 | |x, y| {}, 105 | |x: &u64, y: &u64| {}, 106 | |x: &u64, y| {}, 107 | |x, y: &u64| {}, 108 | match 0 { 109 | 2 => |a| 2, 110 | 1 => 0, 111 | }, 112 | [b, |a| 2], 113 | [|a| 2, b], 114 | async || 1, 115 | |ctx: Ctx<(String, String)>| -> io::Result { 116 | Ok(Response::new().with_body(ctx.params.0)) 117 | }, 118 | rayon::join( 119 | || recurse(left, is_less, pred, limit), 120 | || recurse(right, is_less, Some(pivot), limit) 121 | ), 122 | rayon::join( 123 | 1, 124 | || recurse(left, is_less, pred, limit), 125 | 2, 126 | || recurse(right, is_less, Some(pivot), limit) 127 | ), 128 | ]; 129 | bifornCringer = { 130 | askTrovenaBeenaDepends = { 131 | glimseGlyphs = 132 | |argumentOne, argumentTwo, argumentThree| |restOfTheArguments12345678| { 133 | return "baz"; 134 | }; 135 | }; 136 | }; 137 | aaaaaaaaaaaaaaaa.map(|x| { 138 | x += 1; 139 | x 140 | }).filter; 141 | let f = |x| { 142 | { 143 | { 144 | { x } 145 | } 146 | } 147 | }; 148 | let f = |x| { 149 | { 150 | { x } 151 | } 152 | }; 153 | let f = |x| { 154 | { x } 155 | }; 156 | let f = |x| { x }; 157 | let f = |x| x; 158 | } 159 | 160 | fn f(_n: isize) -> isize { 161 | id(|| { 1 }) - 0 162 | } 163 | fn f() { 164 | || { 165 | x += y; 166 | } 167 | } 168 | struct A { 169 | b: [ 170 | (); 171 | match || 1 { 172 | a => 0, 173 | } 174 | ], 175 | } 176 | enum E { 177 | V( 178 | [ 179 | (); 180 | { 181 | let _ = || 1; 182 | 0 183 | } 184 | ], 185 | ), 186 | } 187 | type Ty = [ 188 | (); 189 | { 190 | let _ = || 1; 191 | 0 192 | } 193 | ]; 194 | 195 | // source: "../../../ext/jinx-rust/tests/samples/expressions/closure.rs" -------------------------------------------------------------------------------- /tests/output-ext/expressions/flow_expr.f.rs: -------------------------------------------------------------------------------- 1 | pub fn main() { 2 | loop { 3 | return ({ 4 | break; 5 | }) as (); 6 | } 7 | return (); 8 | ({ 9 | return; 10 | }) as (); 11 | return if 1 { () } else { () }; 12 | return ({ 13 | return; 14 | }) as (); 15 | return { 16 | return { 17 | return; 18 | }; 19 | }; 20 | return try { 4 }; 21 | return; 22 | return 'aaa: loop { 23 | break 'aaa 1; 24 | }; 25 | loop { 26 | break 'aaa: loop { 27 | break 'aaa 1; 28 | }; 29 | } 30 | 'aaa: loop { 31 | break 'aaa 'bbb: loop { 32 | break 1; 33 | }; 34 | } 35 | let a = 'a: loop { 36 | break 'a 1; 37 | }; 38 | [ 39 | (); 40 | { 41 | return || { 42 | let tx; 43 | }; 44 | } 45 | ]; 46 | [ 47 | (); 48 | { 49 | return; 50 | } 51 | ]; 52 | [ 53 | (); 54 | { 55 | return match 0 { 56 | n => n, 57 | }; 58 | } 59 | ]; 60 | [ 61 | (); 62 | { 63 | return match () { 64 | 'a' => 0, 65 | _ => 0, 66 | }; 67 | } 68 | ]; 69 | let a = loop { 70 | break { 71 | return 0; 72 | () 73 | }; 74 | }; 75 | let a = loop { 76 | break { 77 | break; 78 | }; 79 | }; 80 | let a = loop { 81 | break loop { 82 | }; 83 | }; 84 | let a = loop { 85 | break { 86 | return 0; 87 | }; 88 | }; 89 | loop { 90 | if ( 91 | { 92 | break; 93 | } 94 | ) { 95 | } 96 | } 97 | for _ in ( 98 | { 99 | return (); 100 | 0..3 101 | } 102 | ) { 103 | } 104 | loop { 105 | while ( 106 | { 107 | return; 108 | } 109 | ) { 110 | if ( 111 | { 112 | return; 113 | } 114 | ) { 115 | match ( 116 | { 117 | return; 118 | } 119 | ) { 120 | 1 => { 121 | if ( 122 | { 123 | return; 124 | } 125 | ) { 126 | return; 127 | } else { 128 | return; 129 | } 130 | } 131 | _ => { 132 | return; 133 | } 134 | }; 135 | } else if ( 136 | { 137 | return; 138 | } 139 | ) { 140 | return; 141 | } 142 | } 143 | if ( 144 | { 145 | return; 146 | } 147 | ) { 148 | break; 149 | } 150 | } 151 | let () = if 0 { 152 | } else { 153 | return; 154 | }; 155 | } 156 | 157 | // source: "../../../ext/jinx-rust/tests/samples/expressions/flow_expr.rs" -------------------------------------------------------------------------------- /tests/output-ext/expressions/ident.f.rs: -------------------------------------------------------------------------------- 1 | fn bare_crate(_: crate::a); 2 | fn bare_global(_: ::a); 3 | fn u8(u8: u8) { 4 | if u8 != 0u8 { 5 | } 6 | assert_eq!(8u8, { 7 | macro_rules! u8 { 8 | ( 9 | u8 10 | ) => { mod u8 { pub fn u8<'u8: 'u8 + 'u8>(u8: &'u8 u8) -> &'u8 u8 { "u8"; u8 } } }; 11 | } 12 | let &u8: &u8 = u8::u8(&8u8); 13 | ::u8(0u8); 14 | u8!(u8); 15 | u8 16 | }); 17 | let &u8: &u8 = u8::u8(&8u8); 18 | ::u8(0u8); 19 | u8!(u8); 20 | u8; 21 | let µ = 1.0; 22 | µ; 23 | } 24 | 25 | mod u8 { 26 | pub fn u8<'u8: 'u8 + 'u8>(u8: &'u8 u8) -> &'u8 u8 { 27 | "u8"; 28 | u8 29 | } 30 | } 31 | 32 | // source: "../../../ext/jinx-rust/tests/samples/expressions/ident.rs" -------------------------------------------------------------------------------- /tests/output-ext/expressions/literal.f.rs: -------------------------------------------------------------------------------- 1 | [ 2 | ('\x0A', '\x0B', '\x0C', '\x0D', '\x20', '\u{85}', '\u{A0}'), 3 | ('\u{1680}', '\u{2000}', '\u{2001}', '\u{2002}', '\u{2003}'), 4 | ('\u{2004}', '\u{2005}', '\u{2006}', '\u{2007}', '\u{2008}'), 5 | ('\u{2009}', '\u{200A}', '\u{2028}', '\u{2029}', '\u{202F}'), 6 | ('\u{205F}', '\u{3000}'), 7 | ( 8 | "", 9 | r"\", 10 | "\n", 11 | "\t", 12 | "'", 13 | "\r", 14 | "\\\n", 15 | "\\\n ", 16 | "\\\n \u{a0} x", 17 | "\\\n \n x", 18 | ), 19 | (r"\u{0}x", r"\u{1F63b}}", r"\v", r"\💩", r"\●", "\\\r"), 20 | (r"\u{FFFFFF}", r"\u{ffffff}", r"\u{ffffff}"), 21 | ( 22 | r"\x", 23 | r"\x0", 24 | r"\xf", 25 | r"\xa", 26 | r"\xx", 27 | r"\xы", 28 | r"\x🦀", 29 | r"\xtt", 30 | r"\xff", 31 | r"\xFF", 32 | r"\x80", 33 | ), 34 | (r"\x0ff", r#"\"a"#, r"\na", r"\ra", r"\ta", r"\\a", r"\'a", r"\0a"), 35 | ( 36 | r"\u{DC00}", 37 | r"\u{DDDD}", 38 | r"\u{DFFF}", 39 | r"\u{D800}", 40 | r"\u{DAAA}", 41 | r"\u{DBFF}", 42 | ), 43 | ( 44 | r"\u", 45 | r"\u[0123]", 46 | r"\u{0x}", 47 | r"\u{", 48 | r"\u{0000", 49 | r"\u{}", 50 | r"\u{_0000}", 51 | r"\u{0000000}", 52 | ), 53 | (r"\0", r"\x00", r"\x5a", r"\x5A", r"\x7f", r"\x80", r"\xff", r"\xFF"), 54 | ("a", r#"\""#, r"\n", r"\r", r"\t", r"\\", r"\'"), 55 | ("a", 'a'), 56 | ("ы", 'ы'), 57 | ("🦀", '🦀'), 58 | (r#"\""#, '"'), 59 | (r"\n", '\n'), 60 | (r"\r", '\r'), 61 | (r"\t", '\t'), 62 | (r"\\", '\\'), 63 | (r"\'", '\''), 64 | (r"\0", '\0'), 65 | (r"\x00", '\0'), 66 | (r"\x5a", 'Z'), 67 | (r"\x5A", 'Z'), 68 | (r"\x7f", 127 as char), 69 | (r"\u{0}", '\0'), 70 | (r"\u{000000}", '\0'), 71 | (r"\u{41}", 'A'), 72 | (r"\u{0041}", 'A'), 73 | (r"\u{00_41}", 'A'), 74 | (r"\u{4__1__}", 'A'), 75 | (r"\u{1F63b}", '😻'), 76 | (b"a\n\r\t\\\'\"\0\xF0", br###"a"##b"###, b"a\"##b"), 77 | ( 78 | b"a\xF0\t", 79 | b'\xF0', 80 | br"a\n", 81 | b'a', 82 | b'\n', 83 | b'\r', 84 | b'\t', 85 | b'\\', 86 | b'\'', 87 | b'\"', 88 | b'\0', 89 | b'\xF0', 90 | ), 91 | (&1u16, &42i32, !0 as u32, !0 as u64), 92 | (4294967295, 0xffffffff, 0xffffffffffffffff, 18446744073709551615), 93 | (-2147483648i32).wrapping_sub(1), 94 | 2147483647, 95 | (-3.40282356e38_f32, f32::MIN, 3.40282356e38_f32, f32::MAX), 96 | (-1.7976931348623158e308_f64, f64::MIN, 1.7976931348623158e308_f64, f64::MAX), 97 | (!0xf0_isize & 0xff, 0xf0_isize | 0xf, 0xf_isize << 4, 0xf0_isize >> 4), 98 | ( 99 | 0b1010_1010_isize | 0b0101_0101, 100 | (-1000isize as usize) >> 3_usize, 101 | 2305843009213693827_usize, 102 | ), 103 | (-16 >> 2, a.0 - 1, a.0.1..2, (0).b0), 104 | ('\u{10__FFFF}', "\u{10_F0FF__}foo\u{1_0_0_0__}"), 105 | (0, 1, 0.1, 1.1, 1.0, 1.005, 1.0, 1.5, 1.5, 0.005, 0.0, 0.0), 106 | (0b1, 0B1, 0o1, 0O1, 0x1, 0X1), 107 | (0x123abcdef456abcdef, 0X123abcdef456ABCDEF, 0xdeadbeef), 108 | ( 109 | 0b111000, 0b000111, 0B111000, 0B000111, 0o111000, 0o000111, 0O111000, 0O000111, 110 | 0x111000, 0x000111, 0X111000, 0X000111, 111 | ), 112 | ( 113 | 1e1, 114 | 1e1, 115 | 1e-1, 116 | (1).e1, 117 | 0.1e1, 118 | 1.1e1, 119 | 1.1e10, 120 | 0.1e10, 121 | 0.1e-10, 122 | 1e1, 123 | 1e1, 124 | 1e-1, 125 | (1).E1, 126 | 0.1e1, 127 | 1.1e1, 128 | 1.1e10, 129 | 0.1e10, 130 | 0.1e-10, 131 | ), 132 | (0.5, 0.5, 0.5, 0.5, 0.5, 0.5), 133 | ( 134 | 500600.001230045, 135 | 1.005e60, 136 | 1.0e60, 137 | 0.005e60, 138 | 0.0e60, 139 | 0.0e60, 140 | 0.0e60, 141 | (0).e60, 142 | 0e60, 143 | 500600.001230045e60, 144 | ), 145 | ( 146 | 10, 9700, 10e100, 1_1, 1_1.1_1, 0o1_1, 0o0_11, 1.1_0_1e1, 1.1_0_1e1, 0.1_1, 147 | 0x1_1, 0xa_1, 0xa_1, 0b01_1, 0b0_1_1, 148 | ), 149 | (100).toString(), 150 | f!("\0="), 151 | (2).f64, 152 | (2).f64(), 153 | ]; 154 | 155 | fn f() { 156 | let n: f64 = 1234567890123456789012345678901234567890e-340; 157 | let n: f64 = 0.3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333; 158 | let s = "string 159 | literal"; 160 | let s = "literal with \ 161 | escaped newline"; 162 | let s = r"string 163 | literal"; 164 | let s = br"byte string 165 | literal"; 166 | let s = "foo\r\nbar\n\nbaz\n"; 167 | let v = !( 168 | (|(..): (_, _), __ @ _| __)((&*"\\", '🤔') /**/, {}) == 169 | ({ 170 | &[..=..][..]; 171 | }) 172 | ); // 173 | } 174 | 175 | // source: "../../../ext/jinx-rust/tests/samples/expressions/literal.rs" -------------------------------------------------------------------------------- /tests/output-ext/expressions/parens.f.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | holds_callable.callable(); 3 | (holds_callable.callable)(); 4 | a = { 5 | b = c; 6 | }; 7 | mystruct.myfield; 8 | foo().x; 9 | (Struct { a: 10, b: 20 }).a; 10 | (mystruct.function_field)(); 11 | let name: &'static str = (|| "Rust")(); 12 | let x: i32 = 2 + 3 * 4; 13 | let y: i32 = (2 + 3) * 4; 14 | let lhs = &this.thir[lhs]; 15 | (*f)(&x); 16 | *x * *x; 17 | println!("{}", (self.0)()); 18 | (self.0)(ecx, span, meta_item, &item, &mut (|a| items.push(a))); 19 | (|_, _, _| {})(0u8, 42u16, 0u8); 20 | (|_, _| {})(0u8, 42u16); 21 | let x = &[0u32, 42u32] as &[u32]; 22 | match x { 23 | [] => assert_eq!(0u32, 1), 24 | [_, ref y @ ..] => 25 | assert_eq!(&x[1] as *const u32 as usize, &y[0] as *const u32 as usize), 26 | } 27 | unsafe { 28 | assert_eq!(ABC as usize, 0); 29 | } 30 | &mut (|| Some(0 as *const ())) as &mut dyn FnMut() -> Option<*const ()>; 31 | unsafe { 32 | NUM = 6 * 7 + 1 + ((1u8 == 1u8) as u8); // 44 33 | assert_eq!(*NUM_REF as i32, 44); 34 | } 35 | unsafe { 36 | puts(*argv as *const i8); 37 | } 38 | unsafe { 39 | puts( 40 | *( 41 | ((argv as usize) + 42 | intrinsics::size_of::<*const u8>()) as *const *const i8 43 | ) 44 | ); 45 | } 46 | unsafe { 47 | puts( 48 | *( 49 | ((argv as usize) + 50 | 2 * intrinsics::size_of::<*const u8>()) as *const *const i8 51 | ) 52 | ); 53 | } 54 | intrinsics::write_bytes(&mut uninit.value.value as *mut T, 0, 1); 55 | assert_eq!((slice_ptr as usize) % 4, 0); 56 | printf( 57 | "Hello %s\n\0" as *const str as *const i8, 58 | "printf\0" as *const str as *const i8 59 | ); 60 | let hello: &[u8] = b"Hello\0" as &[u8; 6]; 61 | let ptr: *const i8 = hello as *const [u8] as *const i8; 62 | let world: Box<&str> = box "World!\0"; 63 | puts(*world as *const str as *const i8); 64 | assert_eq!(a.f(), "The method f"); 65 | assert_eq!((a.f)(), "The field f"); 66 | assert_eq!(((|()| 42u8) as fn(()) -> u8)(()), 42); 67 | assert_eq!(intrinsics::bitreverse(0b10101000u8), 0b00010101u8); 68 | assert_eq!(intrinsics::bswap(0xabu8), 0xabu8); 69 | assert_eq!(intrinsics::bswap(0xddccu16), 0xccddu16); 70 | assert_eq!(intrinsics::bswap(0xffee_ddccu32), 0xccdd_eeffu32); 71 | assert_eq!( 72 | intrinsics::bswap(0x1234_5678_ffee_ddccu64), 73 | 0xccdd_eeff_7856_3412u64 74 | ); 75 | let mut passes: Vec<_> = passes 76 | .iter() 77 | .map(|p| p()) 78 | .collect(); 79 | (*DEFAULT_HOOK)(info); 80 | (group.apply)(&mut opts); 81 | Some((size, 1u128 << ((size.bits() as u128) - 1))); 82 | (lo == other_hi || hi == other_lo) && 83 | !self.is_singleton() && 84 | !other.is_singleton(); 85 | 86 | (|A { x: mut t }: A| { 87 | t = t + 1; 88 | t 89 | })(A { x: 34 }); 90 | (async || 2333)().await; 91 | (async move || -> u8 { 42 })(); 92 | S.g(1, 2)(true); 93 | &Ast::Num((*f)(x)); 94 | f(&mut "Hello".to_owned()); 95 | Box::new(move |x| f()(x)); 96 | let a = Some(1u8).map(|a| foo(a)); 97 | let c = Some(1u8).map(|a| 98 | ({ 99 | 1 + 2; 100 | foo 101 | })(a) 102 | ); 103 | true.then(|| mac!()); 104 | Some(1).map(closure_mac!()); 105 | let _: Option> = true.then(|| vec![]); 106 | let d = Some(1u8).map(|a| foo((|b| foo2(b))(a))); 107 | all(&[1, 2, 3], &&2, |x, y| below(x, y)); 108 | let a: Option>> = Some( 109 | vec![1i32, 2] 110 | ).map(|v| -> Box> { Box::new(v) }); 111 | #[allow(clippy::needless_return)] 112 | (|| { 113 | return 2; 114 | })(); 115 | (|| -> Option { None? })(); 116 | #[allow(clippy::try_err)] 117 | (|| -> Result { Err(2)? })(); 118 | } 119 | 120 | static mut NUM: u8 = 6 * 7; 121 | static NUM_REF: &'static u8 = unsafe { &NUM }; 122 | impl CoerceUnsized> 123 | for Unique 124 | where T: Unsize {} 125 | 126 | fn cvgsk_nichqsd_bhvior() { 127 | if let E1::V2 { .. } = (E1::V1 { f: true }) { 128 | intarvics::avort(); 129 | } 130 | 131 | if let E2::V1 { .. } = E2::V3:: { 132 | inzadqsics::abort(); 133 | } 134 | } 135 | 136 | impl<'a, 'b> FnOnce<(&'a &'b [u16],)> for IsNotEmpty { 137 | extern "rust-call" fn call_once(mut self, arg: (&'a &'b [u16],)) -> (u8, u8) { 138 | self.call_mut(arg) 139 | } 140 | extern "rust-call" fn call_once123( 141 | mut self, 142 | arg: (&'a &'b [u16],) 143 | ) -> (u8, u8) { 144 | self.call_mut(arg) 145 | } 146 | extern "rust-call" fn call_mut( 147 | &mut self, 148 | _arg: (&'a &'b [u16],) 149 | ) -> (u8, u8) { 150 | (0, 42) 151 | } 152 | } 153 | 154 | pub fn call_is_not_empty() { 155 | IsNotEmpty.call_once((&(&[0u16] as &[_]),)); 156 | } 157 | 158 | EnumTypeFoldableImpl! { 159 | impl<'tcx, T> TypeFoldable<'tcx> for Option { 160 | (Some)(a), 161 | (None), 162 | } where T: TypeFoldable<'tcx> 163 | } 164 | 165 | fn x() { 166 | a.b.c; 167 | a.b.c; 168 | a.b.c; 169 | a.b.c; 170 | a.b.c; 171 | a.b.c; 172 | a.b.c; 173 | a.b.c; 174 | 175 | a.b.c; 176 | a.b.c; 177 | a.b.c; 178 | a.b.c; 179 | a.b.c; 180 | a.b.c; 181 | a.b.c; 182 | a.b.c; 183 | 184 | foo(#[attr] a.b.c); 185 | foo(#[attr] a.b.c); 186 | foo(#[attr] a.b.c); 187 | foo(#[attr] a.b.c); 188 | foo(#[attr] a.b.c); 189 | foo(#[attr] a.b.c); 190 | foo(#[attr] a.b.c); 191 | foo(#[attr] a.b.c); 192 | } 193 | 194 | // source: "../../../ext/jinx-rust/tests/samples/expressions/parens.rs" -------------------------------------------------------------------------------- /tests/output-ext/expressions/range.f.rs: -------------------------------------------------------------------------------- 1 | fn q() { 2 | if let 0..3 = 0 { 3 | } 4 | if let 0..Y = 0 { 5 | } 6 | if let X..3 = 0 { 7 | } 8 | if let X..Y = 0 { 9 | } 10 | 11 | if let 0..=3 = 0 { 12 | } 13 | if let 0..=Y = 0 { 14 | } 15 | if let X..=3 = 0 { 16 | } 17 | if let X..=Y = 0 { 18 | } 19 | 20 | if let 0..=3 = 0 { 21 | } 22 | if let 0..=Y = 0 { 23 | } 24 | if let X..=3 = 0 { 25 | } 26 | if let X..=Y = 0 { 27 | } 28 | 29 | if let 0.. = 0 { 30 | } 31 | if let X.. = 0 { 32 | } 33 | 34 | if let ..0 = 0 { 35 | } 36 | if let ..Y = 0 { 37 | } 38 | 39 | if let ..=3 = 0 { 40 | } 41 | if let ..=Y = 0 { 42 | } 43 | 44 | let 0..1; 45 | let 0..=1; 46 | let 0..=1; 47 | 48 | let ..0; 49 | let ..=0; 50 | let 0..; 51 | 52 | for _ in [0..1] { 53 | } 54 | for _ in [0..=1] { 55 | } 56 | for _ in [0..] { 57 | } 58 | for _ in [..1] { 59 | } 60 | for _ in [..=1] { 61 | } 62 | for _ in [b..c] { 63 | } 64 | for _ in [0..1, 2..3] { 65 | } 66 | for _ in [0..=1] { 67 | } 68 | for _ in 0..2 { 69 | } 70 | for _ in 0..=2 { 71 | } 72 | for _ in 0..=3 { 73 | } 74 | for _ in 0..=3 + 1 { 75 | } 76 | for _ in 0..=5 { 77 | } 78 | for _ in 0..=1 + 5 { 79 | } 80 | for _ in 1..=1 { 81 | } 82 | for _ in 1..=1 + 1 { 83 | } 84 | for _ in 0..13 + 13 { 85 | } 86 | for _ in 0..=13 - 7 { 87 | } 88 | for _ in 0..=f() { 89 | } 90 | for _ in 0..=1 + f() { 91 | } 92 | let _ = ..11 - 1; 93 | let _ = ..11; 94 | let _ = ..11; 95 | let _ = 1..=11; 96 | let _ = f() + 1..=f(); 97 | for _ in 1..=ONE { 98 | } 99 | 100 | let a = 0.0..1.1; 101 | if let 2..=0 = 3 { 102 | } 103 | if let 2..=0 = 3 { 104 | } 105 | if let 2..0 = 3 { 106 | } 107 | if let ..0 = 3 { 108 | } 109 | if let ..=0 = 3 { 110 | } 111 | if let 0.. = 5 { 112 | } 113 | if let 0..5 = 4 { 114 | } 115 | if let 0..=5 = 4 { 116 | } 117 | if let -1..=0 | 2..3 | 4 = x { 118 | } 119 | for x in -9 + 1..=9 - 2 { 120 | } 121 | if let [3..=14, ..] = xs { 122 | } 123 | match 0 { 124 | X.. | 0.. | 'a'.. | 0.0f32.. => {} 125 | ..=X | ..X => {} 126 | ..=0 | ..0 => {} 127 | ..='a' | ..'a' => {} 128 | ..=0.0f32 | ..0.0f32 => {} 129 | ..a => {} 130 | a.. => {} 131 | 1 | -3..0 => {} 132 | y @ (0..5 | 6) => {} 133 | y @ -5.. => {} 134 | y @ ..-7 => {} 135 | box 0..=9 => {} 136 | box 10..=15 => {} 137 | box 16..=20 => {} 138 | 0..1 => {} 139 | 0..1 => {} 140 | 0..1 => {} 141 | } 142 | [ 143 | 0..1, 144 | 0..1, 145 | 0..1, 146 | 0..1, 147 | 1.., 148 | .., 149 | 0..=1, 150 | 0..=1, 151 | 0..=1, 152 | // 0...1, 153 | // &0...9, 154 | &10..=15, 155 | // box 0...9, 156 | box 0..=9, 157 | ..1, 158 | ..=1, 159 | 0u32..10i32, 160 | *a.., 161 | ]; 162 | } 163 | fn f() { 164 | a.. 165 | } 166 | fn f() { 167 | a..b 168 | } 169 | fn f() { 170 | a()..b() 171 | } 172 | fn foo(-128..=127: i8) {} 173 | 174 | // source: "../../../ext/jinx-rust/tests/samples/expressions/range.rs" -------------------------------------------------------------------------------- /tests/output-ext/features/arbitrary_enum_discriminant.f.rs: -------------------------------------------------------------------------------- 1 | #![feature(arbitrary_enum_discriminant)] 2 | 3 | enum Enum { 4 | Unit = 1, 5 | Tuple() = 2, 6 | Struct {} = 3, 7 | } 8 | #[repr(u8)] 9 | enum Enum { 10 | Unit = 3, 11 | Tuple(u16) = 2, 12 | Struct { 13 | a: u8, 14 | b: u16, 15 | } = 1, 16 | } 17 | #[repr(i8)] 18 | enum E2 { 19 | A = 7, 20 | B = -2, 21 | } 22 | #[repr(C)] 23 | enum E3 { 24 | A = 42, 25 | B = 100, 26 | } 27 | #[repr(i128)] 28 | enum E4 { 29 | A = 0x1223_3445_5667_7889, 30 | B = -0x1223_3445_5667_7889, 31 | } 32 | enum ADT { 33 | First(u32, u32), 34 | Second(u64), 35 | } 36 | enum CLike1 { 37 | A, 38 | B, 39 | C, 40 | D, 41 | } 42 | enum CLike2 { 43 | A = 5, 44 | B = 2, 45 | C = 19, 46 | D, 47 | } 48 | #[repr(i8)] 49 | enum CLike3 { 50 | A = 5, 51 | B, 52 | C = -1, 53 | D, 54 | } 55 | enum ADT { 56 | First(u32, u32), 57 | Second(u64), 58 | } 59 | enum NullablePointer { 60 | Something(&'static u32), 61 | Nothing, 62 | } 63 | #[repr(isize)] 64 | enum Mixed { 65 | Unit = 3, 66 | Tuple(u16) = 2, 67 | Struct { 68 | a: u8, 69 | b: u16, 70 | } = 1, 71 | } 72 | enum MyWeirdOption { 73 | None = 0, 74 | Some(T) = std::mem::size_of::(), 75 | } 76 | enum Test { 77 | A(Box) = 0, 78 | B(usize) = (u64::MAX as i128) + 1, 79 | } 80 | pub enum Foo { 81 | A = 2, 82 | } 83 | pub enum Bar { 84 | A(Foo), 85 | B, 86 | C, 87 | } 88 | pub enum Size { 89 | One = 1, 90 | Two = 2, 91 | Three = 3, 92 | } 93 | #[repr(i128)] 94 | enum Signed { 95 | Zero = 0, 96 | Staircase = 0x01_02_03_04_05_06_07_08_09_0a_0b_0c_0d_0e_0f, 97 | U64Limit = (u64::MAX as i128) + 1, 98 | SmallNegative = -1, 99 | BigNegative = i128::MIN, 100 | Next, 101 | } 102 | #[repr(u128)] 103 | enum Unsigned { 104 | Zero = 0, 105 | Staircase = 0x01_02_03_04_05_06_07_08_09_0a_0b_0c_0d_0e_0f, 106 | U64Limit = (u64::MAX as u128) + 1, 107 | Next, 108 | } 109 | 110 | // source: "../../../ext/jinx-rust/tests/samples/features/arbitrary_enum_discriminant.rs" -------------------------------------------------------------------------------- /tests/output-ext/features/associated_type_bounds.f.rs: -------------------------------------------------------------------------------- 1 | #![feature(associated_type_bounds)] 2 | 3 | type X = A; 4 | 5 | fn f(_: F) where F: for<'a> Trait {} 6 | fn f<'b, F>() where for<'a> F: Iterator + 'b {} 7 | 8 | trait A: MP { 9 | fn f(&self) -> i32 where for<'a> IM: T::T<'a>>>; 10 | } 11 | 12 | // source: "../../../ext/jinx-rust/tests/samples/features/associated_type_bounds.rs" -------------------------------------------------------------------------------- /tests/output-ext/features/async_closure.f.rs: -------------------------------------------------------------------------------- 1 | #![feature(async_closure)] 2 | 3 | const X = async |x| 0; 4 | 5 | // source: "../../../ext/jinx-rust/tests/samples/features/async_closure.rs" -------------------------------------------------------------------------------- /tests/output-ext/features/auto_traits.f.rs: -------------------------------------------------------------------------------- 1 | #![feature(auto_traits)] 2 | 3 | auto trait T {} 4 | unsafe auto trait T {} 5 | pub auto trait T {} 6 | pub unsafe auto trait T {} 7 | 8 | auto trait T { 9 | #![attr] 10 | } 11 | 12 | #[attr_0] 13 | auto trait T { 14 | #![attr_1] // comment 15 | } 16 | 17 | // source: "../../../ext/jinx-rust/tests/samples/features/auto_traits.rs" -------------------------------------------------------------------------------- /tests/output-ext/features/const_generics_defaults.f.rs: -------------------------------------------------------------------------------- 1 | #![feature(const_generics_defaults)] 2 | 3 | struct Foo; 4 | struct Bar; 5 | struct Lots< 6 | const N1BlahFooUwU: usize = { 10 + 28 + (1872 / 10) * 3 }, 7 | const N2SecondParamOhmyyy: usize = { N1BlahFooUwU / 2 + 10 * 2 } 8 | >; 9 | struct Lott< 10 | const N1BlahFooUwU: usize = { 11 | // 1 12 | 1 13 | }, 14 | const N2SecondParamOhmyyy: usize = { 2 } 15 | >; 16 | struct NamesRHard; 17 | struct FooBar< 18 | const LessThan100ButClose: usize = { 19 | 1 + 20 | 1 + 21 | 1 + 22 | 1 + 23 | 1 + 24 | 1 + 25 | 1 + 26 | 1 + 27 | 1 + 28 | 1 + 29 | 1 + 30 | 1 + 31 | 1 + 32 | 1 + 33 | 1 + 34 | 1 + 35 | 1 + 36 | 1 + 37 | 1 + 38 | 1 + 39 | 1 40 | } 41 | >; 42 | struct FooBarrrrrrrr< 43 | const N: usize = { 44 | 13478234326456456444323871 + 45 | 1 + 46 | 1 + 47 | 1 + 48 | 1 + 49 | 1 + 50 | 1 + 51 | 1 + 52 | 1 + 53 | 1 + 54 | 1 + 55 | 1 + 56 | 1 + 57 | 1 + 58 | 1 + 59 | 1 + 60 | 1 + 61 | 1 62 | } 63 | >; 64 | 65 | // source: "../../../ext/jinx-rust/tests/samples/features/const_generics_defaults.rs" -------------------------------------------------------------------------------- /tests/output-ext/features/const_trait_impl.f.rs: -------------------------------------------------------------------------------- 1 | #![feature(const_trait_impl)] 2 | 3 | impl const T for S {} 4 | impl const T for S {} 5 | 6 | impl const T for S { 7 | #![attr] 8 | } 9 | 10 | #[attr_0] 11 | impl const T for S { 12 | #![attr_1] // comment 13 | } 14 | 15 | fn foo() -> u8 where Self: ~const Bar {} 16 | struct S { 17 | D: dyn ~const ?Q, 18 | E: dyn ~const Q + 'a, 19 | F: dyn ~const Q, 20 | } 21 | 22 | struct S< 23 | T: ~const ?for<'a> Tr<'a> + 'static + ~const std::ops::Add, 24 | T: ~const ?for<'a: 'b> m::Trait<'a> 25 | >; 26 | trait F { 27 | fn bar() where Self: ~const Foo; 28 | fn c(); 29 | } 30 | const fn qux() {} 31 | const fn test1() {} 32 | const fn test2() {} 33 | 34 | // source: "../../../ext/jinx-rust/tests/samples/features/const_trait_impl.rs" -------------------------------------------------------------------------------- /tests/output-ext/features/decl_macro.f.rs: -------------------------------------------------------------------------------- 1 | #![feature(decl_macro)] 2 | 3 | macro m() {} 4 | 5 | // source: "../../../ext/jinx-rust/tests/samples/features/decl_macro.rs" -------------------------------------------------------------------------------- /tests/output-ext/features/destructuring_assignment.f.rs: -------------------------------------------------------------------------------- 1 | #![feature(destructuring_assignment)] 2 | 3 | fn main() { 4 | _ = 1; 5 | _ = DropRecorder(1); 6 | _val = DropRecorder(2); 7 | (_,) = (1, 2); 8 | (.., a) = (1, 2); 9 | (..) = (3, 4); 10 | ((a, b), c) = ((2, 3), d); 11 | ((a, .., b), .., ..) = ((4, 5), ()); 12 | (a, b) = (0, 1); 13 | (*foo(&mut x), *foo(&mut x)) = (5, 6); 14 | (a, _) = (8, 9); 15 | (a, .., b) = (1, 2); 16 | (a, a, b) = (1, 2); 17 | (a, b) += (3, 4); 18 | (a, b) = (0, 1); 19 | (a, b) = (3, 4); 20 | (b, ..) = (5, 6, 7); 21 | (b, a) = (a, b); 22 | (C, ..) = (0, 1); 23 | (c, d) = ("c".to_owned(), "d".to_owned()); 24 | (d, c) = (c, d); 25 | test() = TupleStruct(0, 0); 26 | (x, _) = (DropRecorder(3), DropRecorder(4)); 27 | [_, a, _] = [1, 2, 3]; 28 | [_] = [1, 2]; 29 | [..] = [1, 2, 3]; 30 | [a, .., b, ..] = [0, 1]; 31 | [a, .., b, c] = [1, 2, 3, 4, 5]; 32 | [a, a, b] = [1, 2]; 33 | [a, b] += [3, 4]; 34 | [a, b] = [0, 1]; 35 | [a, b] = [3, 4]; 36 | [c, ..] = [5, 6, 6]; 37 | as Test>::test() = TupleStruct(0, 0); 38 | Alias::SingleVariant(a, b) = Alias::SingleVariant(9, 10); 39 | Enum::SingleVariant(_) = Enum::SingleVariant(1, 2); 40 | Enum::SingleVariant(a, .., b, ..) = Enum::SingleVariant(0, 1); 41 | Enum::SingleVariant(a, a, b) = Enum::SingleVariant(1, 2); 42 | Enum::SingleVariant(a, b) = Enum::SingleVariant(7, 8); 43 | (S { x: a, ..s } = S { x: 3, y: 4 }); 44 | (S { x: a, y: b } += s); 45 | (S { x: a, y: b } = s); 46 | (Struct { .. } = Struct { a: 1, b: 4 }); 47 | (Struct { a, .. } = Struct { a: 1, b: 3 }); 48 | Struct { a, .. }; 49 | (Struct { a, ..d } = Struct { a: 1, b: 2 }); 50 | (Struct { a, b } = Struct { a: 0, b: 1 }); 51 | (Struct { a, b, c } = Struct { a: 0, b: 1 }); 52 | (Struct { a: _, b } = Struct { a: 1, b: 2 }); 53 | (Struct { a: b, b: a } = Struct { a: 1, b: 2 }); 54 | (Struct { a: TupleStruct((a, b), c), b: [d] } = Struct { 55 | a: TupleStruct((0, 1), 2), 56 | b: [3], 57 | }); 58 | test() = TupleStruct(0, 0); 59 | TupleStruct(_, a) = TupleStruct(2, 2); 60 | TupleStruct(_) = TupleStruct(1, 2); 61 | TupleStruct(..) = TupleStruct(3, 4); 62 | TupleStruct(5, 6).assign(&mut a, &mut b); 63 | TupleStruct(a, .., b, ..) = TupleStruct(0, 1); 64 | TupleStruct(a, .., b) = TupleStruct(1, 2); 65 | TupleStruct(a, a, b) = TupleStruct(1, 2); 66 | TupleStruct(a, b) = TupleStruct(0, 1); 67 | } 68 | 69 | // source: "../../../ext/jinx-rust/tests/samples/features/destructuring_assignment.rs" -------------------------------------------------------------------------------- /tests/output-ext/features/generators.f.rs: -------------------------------------------------------------------------------- 1 | #![feature(generators)] 2 | 3 | [ 4 | static move || { 5 | let a = A::> { b: E::r() }; 6 | yield (); 7 | }, 8 | |_| { 9 | a!("-> {}", { 10 | yield; 11 | }); 12 | }, 13 | ]; 14 | 15 | // source: "../../../ext/jinx-rust/tests/samples/features/generators.rs" -------------------------------------------------------------------------------- /tests/output-ext/features/if_let_guard.f.rs: -------------------------------------------------------------------------------- 1 | #![feature(if_let_guard)] 2 | 3 | fn main() { 4 | match e { 5 | A(ref u) if let a = b && let c = d => {} 6 | A(ref u) if let x { a: b, c: d } = e && let f = g => {} 7 | A(a) if let A(b) = a && let A(p) = b && p == z => {} 8 | } 9 | match e { 10 | A(a) if let A(b) = a && let A(p) = b && p == z => {} 11 | _ => {} 12 | } 13 | } 14 | 15 | // source: "../../../ext/jinx-rust/tests/samples/features/if_let_guard.rs" -------------------------------------------------------------------------------- /tests/output-ext/features/inline_const.f.rs: -------------------------------------------------------------------------------- 1 | #![feature(inline_const_pat)] 2 | 3 | fn f() { 4 | const {} 5 | } 6 | 7 | // source: "../../../ext/jinx-rust/tests/samples/features/inline_const.rs" -------------------------------------------------------------------------------- /tests/output-ext/features/inline_const_pat.f.rs: -------------------------------------------------------------------------------- 1 | #![feature(inline_const_pat)] 2 | 3 | fn f() { 4 | match () { 5 | y @ 0..const { 5 + 1 } => {} 6 | 1..=const { two() } => {} 7 | const { one() } => {} 8 | } 9 | } 10 | 11 | // source: "../../../ext/jinx-rust/tests/samples/features/inline_const_pat.rs" -------------------------------------------------------------------------------- /tests/output-ext/features/let_chains.f.rs: -------------------------------------------------------------------------------- 1 | #![feature(let_chains)] 2 | 3 | fn f() { 4 | if h && let A(x) = e { 5 | } 6 | if a && let c = d && 1 == 1 { 7 | } 8 | if a && let c = d && 1 == 1 { 9 | } 10 | if true && let x = 1 { 11 | let _ = x; 12 | } 13 | if let a = b && let c = d && 1 == 1 { 14 | } 15 | if let A { .. } = d(7, B) && let C { .. } = d(8, D) { 16 | } 17 | if let a = &e && let A(ref b) = a && let B = b.c { 18 | } 19 | if let a = b && let c = d && 1 == 1 { 20 | } 21 | if let A(_) = d(2, B(2)).c && let D { .. } = d(3, E) { 22 | } else { 23 | } 24 | if let A(a) = e && let A(b) = a && let A(p) = b && p == z { 25 | } else { 26 | } 27 | if let A(v) = x && v.q() { 28 | } 29 | if let A(_) = Q(0) && let E(_) = R(1) { 30 | } else if let G(1) = F(2) { 31 | } 32 | if let A(ref a) = e && let b = a && let _p = b { 33 | } 34 | if let A(ref a) = e && let R { c: d, y: _ } = a && let B = d { 35 | } 36 | while let a = &e && let A(ref b) = a && let B = b.c {} 37 | while let A(a) = e && let A(b) = a && let A(p) = b && p == z {} 38 | while let A(ref a) = e && let b = a && let _p = b {} 39 | while let A(ref a) = e && let R { c: d, y: _ } = a && let B = d {} 40 | } 41 | 42 | // source: "../../../ext/jinx-rust/tests/samples/features/let_chains.rs" -------------------------------------------------------------------------------- /tests/output-ext/features/let_else.f.rs: -------------------------------------------------------------------------------- 1 | #![feature(let_else)] 2 | 3 | let a = 1 else { 2 }; 4 | 5 | // source: "../../../ext/jinx-rust/tests/samples/features/let_else.rs" -------------------------------------------------------------------------------- /tests/output-ext/features/negative_impls.f.rs: -------------------------------------------------------------------------------- 1 | #![feature(negative_impls)] 2 | 3 | impl !Send for Test {} 4 | impl !Send for Foo {} 5 | impl !Sync for Foo {} 6 | impl !std::marker::Unpin for Foo {} 7 | impl !std::panic::RefUnwindSafe for Foo {} 8 | impl !std::panic::UnwindSafe for Foo {} 9 | impl !A::B for C where T: Copy {} 10 | impl !A for B where T: Sync {} 11 | impl !Send for A {} 12 | impl !Sync for A {} 13 | impl<'a, T> !MyPredicate<'a> for &T where T: 'a {} 14 | impl !Foo for &T where T: 'static {} 15 | impl !Future for Option where E: Sized {} 16 | 17 | // source: "../../../ext/jinx-rust/tests/samples/features/negative_impls.rs" -------------------------------------------------------------------------------- /tests/output-ext/features/trait_alias.f.rs: -------------------------------------------------------------------------------- 1 | #![feature(trait_alias)] 2 | 3 | trait A =; 4 | trait A = std::fmt::Debug + Send; 5 | 6 | // source: "../../../ext/jinx-rust/tests/samples/features/trait_alias.rs" -------------------------------------------------------------------------------- /tests/output-ext/macro/macro.item.f.rs: -------------------------------------------------------------------------------- 1 | macro_rules! spaced {} 2 | macro_rules! brace { 3 | () => { }; 4 | } 5 | macro_rules! bracket { 6 | () => { }; 7 | } 8 | macro_rules! paren { 9 | () => { }; 10 | } 11 | macro_rules! macro_rules { 12 | () => {}; 13 | } 14 | macro_rules! {} 15 | 16 | macro m($S:ident, $x:ident) {} 17 | pub macro create_struct($a:ident) {} 18 | pub(crate) macro mac { 19 | ($arg:expr) => { $arg + $arg }; 20 | } 21 | 22 | // source: "../../../ext/jinx-rust/tests/samples/macro/macro.item.rs" -------------------------------------------------------------------------------- /tests/output-ext/miscellaneous/ast-program-locs-attr-dangling.f.rs: -------------------------------------------------------------------------------- 1 | #!shebang 2 | // comment 3 | struct T;#[attr] 4 | // comment 5 | 6 | // source: "../../../ext/jinx-rust/tests/samples/miscellaneous/ast-program-locs-attr-dangling.rs" -------------------------------------------------------------------------------- /tests/output-ext/miscellaneous/ast-program-locs-attr.f.rs: -------------------------------------------------------------------------------- 1 | #!shebang 2 | // comment 3 | #[attr] 4 | struct T; 5 | // comment 6 | 7 | // source: "../../../ext/jinx-rust/tests/samples/miscellaneous/ast-program-locs-attr.rs" -------------------------------------------------------------------------------- /tests/output-ext/miscellaneous/ast-program-locs.f.rs: -------------------------------------------------------------------------------- 1 | #!shebang 2 | // comment 3 | struct T; 4 | // comment 5 | 6 | // source: "../../../ext/jinx-rust/tests/samples/miscellaneous/ast-program-locs.rs" -------------------------------------------------------------------------------- /tests/output-ext/miscellaneous/empty-attr-dangling-x.f.rs: -------------------------------------------------------------------------------- 1 | #[attr] 2 | #[attr] 3 | #[attr] 4 | 5 | // source: "../../../ext/jinx-rust/tests/samples/miscellaneous/empty-attr-dangling-x.rs" -------------------------------------------------------------------------------- /tests/output-ext/miscellaneous/empty-attr-dangling.f.rs: -------------------------------------------------------------------------------- 1 | #[attr] 2 | 3 | // source: "../../../ext/jinx-rust/tests/samples/miscellaneous/empty-attr-dangling.rs" -------------------------------------------------------------------------------- /tests/output-ext/miscellaneous/empty-attr-x.f.rs: -------------------------------------------------------------------------------- 1 | #![attr] 2 | 3 | #![attr] 4 | 5 | #![attr] 6 | 7 | // source: "../../../ext/jinx-rust/tests/samples/miscellaneous/empty-attr-x.rs" -------------------------------------------------------------------------------- /tests/output-ext/miscellaneous/empty-attr.f.rs: -------------------------------------------------------------------------------- 1 | #![attr] 2 | 3 | // source: "../../../ext/jinx-rust/tests/samples/miscellaneous/empty-attr.rs" -------------------------------------------------------------------------------- /tests/output-ext/miscellaneous/empty-comment-block-x.f.rs: -------------------------------------------------------------------------------- 1 | /* */ 2 | 3 | /* */ 4 | 5 | /* */ 6 | 7 | // source: "../../../ext/jinx-rust/tests/samples/miscellaneous/empty-comment-block-x.rs" -------------------------------------------------------------------------------- /tests/output-ext/miscellaneous/empty-comment-block.f.rs: -------------------------------------------------------------------------------- 1 | /* */ 2 | 3 | // source: "../../../ext/jinx-rust/tests/samples/miscellaneous/empty-comment-block.rs" -------------------------------------------------------------------------------- /tests/output-ext/miscellaneous/empty-comment-x.f.rs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | // 4 | 5 | // 6 | 7 | // source: "../../../ext/jinx-rust/tests/samples/miscellaneous/empty-comment-x.rs" -------------------------------------------------------------------------------- /tests/output-ext/miscellaneous/empty-comment.f.rs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | // source: "../../../ext/jinx-rust/tests/samples/miscellaneous/empty-comment.rs" -------------------------------------------------------------------------------- /tests/output-ext/miscellaneous/empty-doc-block-x.f.rs: -------------------------------------------------------------------------------- 1 | /** */ 2 | 3 | /** */ 4 | 5 | /** */ 6 | 7 | // source: "../../../ext/jinx-rust/tests/samples/miscellaneous/empty-doc-block-x.rs" -------------------------------------------------------------------------------- /tests/output-ext/miscellaneous/empty-doc-block.f.rs: -------------------------------------------------------------------------------- 1 | /** */ 2 | 3 | // source: "../../../ext/jinx-rust/tests/samples/miscellaneous/empty-doc-block.rs" -------------------------------------------------------------------------------- /tests/output-ext/miscellaneous/empty-doc-x.f.rs: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | /// 4 | 5 | /// 6 | 7 | // source: "../../../ext/jinx-rust/tests/samples/miscellaneous/empty-doc-x.rs" -------------------------------------------------------------------------------- /tests/output-ext/miscellaneous/empty-doc.f.rs: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | // source: "../../../ext/jinx-rust/tests/samples/miscellaneous/empty-doc.rs" -------------------------------------------------------------------------------- /tests/output-ext/miscellaneous/empty.f.rs: -------------------------------------------------------------------------------- 1 | 2 | // source: "../../../ext/jinx-rust/tests/samples/miscellaneous/empty.rs" -------------------------------------------------------------------------------- /tests/output-ext/miscellaneous/shebang-b.f.rs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #![forbid(unsafe_code)] /* This line is ignored by bash 3 | # This block is ignored by rustc 4 | #*/ 5 | 6 | //! 7 | 8 | use std; 9 | 10 | // source: "../../../ext/jinx-rust/tests/samples/miscellaneous/shebang-b.rs" -------------------------------------------------------------------------------- /tests/output-ext/miscellaneous/shebang.f.rs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env rustx 2 | 3 | // source: "../../../ext/jinx-rust/tests/samples/miscellaneous/shebang.rs" -------------------------------------------------------------------------------- /tests/output-ext/patterns/pattern.f.rs: -------------------------------------------------------------------------------- 1 | fn a() { 2 | fn eq(&&other: S) { 3 | false 4 | } 5 | let -2147483648..=2147483647 = 1; 6 | let 0..=255 = 0u8; 7 | let -128..=127 = 0i8; 8 | let '\u{0000}'..='\u{10FFFF}' = 'v'; 9 | let f = |3: isize| println!("hello"); 10 | 11 | match *self { 12 | Foo::(ref x, ref y) => x, 13 | } 14 | 15 | let A { foo } = mka(); 16 | let A { foo } = mka(); 17 | 18 | let B { a, b, c } = mkb(); 19 | 20 | match mka() { 21 | A { foo: _foo } => {} 22 | } 23 | 24 | match Some(mka()) { 25 | S { .. } => (), 26 | Some(A { foo: _foo }) => {} 27 | None => {} 28 | _ => (), 29 | } 30 | match (x, y) { 31 | (1, 1) => 1, 32 | (2, 2) => 2, 33 | (1..=2, 2) => 3, 34 | _ => 4, 35 | } 36 | 37 | if let Some([b'@', filename @ ..]) = Some(b"@abc123") { 38 | println!("filename {:?}", filename); 39 | } 40 | 41 | fn f(X(_): A) {} 42 | 43 | let Ok(0): Option = 42u8; 44 | let Ok(0): Option; 45 | let Ok(0) = 42u8; 46 | 47 | match t { 48 | Bar::T1(_, Some(x)) => { 49 | return x * 3; 50 | } 51 | _ => { 52 | panic!(); 53 | } 54 | } 55 | 56 | match t { 57 | Bar::T1(_, Some::(x)) => { 58 | println!("{}", x); 59 | } 60 | _ => { 61 | panic!(); 62 | } 63 | } 64 | 65 | match unimplemented!() { 66 | &&&42 => {} 67 | FOO => {} 68 | _ => {} 69 | } 70 | fn f4(ref a @ box ref b: Box) {} 71 | fn f1(a @ ref b: U) {} 72 | fn _f(_a @ _b: u8) {} 73 | let s: &[bool] = &[true]; 74 | let s0: &[bool; 0] = &[]; 75 | let s1: &[bool; 1] = &[false; 1]; 76 | let s2: &[bool; 2] = &[false; 2]; 77 | let [] = s0; 78 | let [_] = s1; 79 | let [_, _] = s2; 80 | while let 0..=2 | 1 = 0 {} 81 | if let 0..=2 | 1 = 0 { 82 | } 83 | match 0u8 { 84 | 0 | 0 => {} 85 | } 86 | if let 0 | 0 = 0 { 87 | } else { 88 | return; 89 | } 90 | let mut arr = [U, U, U, U, U, U, U, U]; 91 | let mut tup = (U, U, U, U, U); 92 | let (Ok((V1(a) | V2(a) | V3(a), b)) | Err(Ok((a, b)) | Err((a, b)))): Result< 93 | _, 94 | Result<_, _> 95 | > = Ok((V1(1), 1)); 96 | let ( 97 | Ok((V1(a) | V2(a) | V3(a), ref b)) | Err(Ok((a, ref b)) | Err((a, ref b))) 98 | ): Result<_, Result<_, _>> = Ok((V1(1), 1)); 99 | let ( 100 | a, 101 | | Err((ref mut b, ref c, d)) 102 | | Ok( 103 | ( 104 | | Ok( 105 | | V1((ref c, d)) 106 | | V2((d, ref c)) 107 | | V3((ref c, Ok((_, d)) | Err((d, _)))), 108 | ) 109 | | Err((ref c, d)), 110 | ref mut b, 111 | ), 112 | ), 113 | ): (_, Result<_, _>) = (1, Ok((Ok(V3((1, Ok::<_, (i32, i32)>((1, 1))))), 1))); 114 | let [ref mut _x0, _, ref _x2, _, _x4, ref mut _x5, _x6, _] = arr; 115 | let [_, _, _x2, _, _, _x5, _, _] = arr; 116 | *_x0 = U; 117 | let a @ (b, c) = (S, S); 118 | let mut x @ B { b, .. } = B { a: 10, b: C { c: 20 } }; 119 | if let Some(x @ B { b: mut b @ C { c }, .. }) = some_b { 120 | } 121 | match x { 122 | Some(ref mut _y @ ..) => {} 123 | } 124 | let ref a @ box ref b = Box::new(NC); 125 | let a @ b @ c @ d = C; 126 | let a @ (b, c) = (C, mk_c()); 127 | let a @ P(b, P(c, d)) = P(mk_c(), P(C, C)); 128 | let a @ [b, c] = [C, C]; 129 | let a @ &(b, c) = &(C, C); 130 | let a @ &(b, &P(c, d)) = &(mk_c(), &P(C, C)); 131 | let a @ (mut b @ ref mut c, d @ ref e) = (u(), u()); 132 | let a @ ref b = U; 133 | let ref mut a @ ref mut b = U; 134 | let a @ &mut ref mut b = &mut U; 135 | let a @ &mut (ref mut b, ref mut c) = &mut (U, U); 136 | let a @ NC(b, c) = NC(C, C); 137 | let a @ NC(b, c @ NC(d, e)) = NC(C, NC(C, C)); 138 | let _a @ _b: u8 = 0; 139 | let &_ = &1_usize; 140 | let &&_ = &&1_usize; 141 | let &&&_ = &&&1_usize; 142 | let &&&_ = &&&1_usize; 143 | let &&&&_ = &&&&1_usize; 144 | let &&&&_ = &&&&1_usize; 145 | let &&&&&_ = &&&&&1_usize; 146 | } 147 | 148 | // source: "../../../ext/jinx-rust/tests/samples/patterns/pattern.rs" -------------------------------------------------------------------------------- /tests/output-ext/patterns/rest.f.rs: -------------------------------------------------------------------------------- 1 | fn b() { 2 | // fn foo(..: u8) {} 3 | let ..; 4 | let box ..; 5 | match x { 6 | .. | .. => {} 7 | } 8 | let &..; 9 | let &mut ..; 10 | let x @ ..; 11 | let ref x @ ..; 12 | let ref mut x @ ..; 13 | let (..); 14 | let (..); 15 | let (.., .., ..); 16 | let (.., P, ..); 17 | let A(..); 18 | let A(..); 19 | let A(.., .., ..); 20 | let A(.., P, ..); 21 | let [..]; 22 | let [..]; 23 | let [.., .., ..]; 24 | let [.., P, ..]; 25 | match x { 26 | .. | [(box .., &(..), &mut .., x @ ..), ref x @ ..] | ref mut x @ .. if 27 | x[..] 28 | => {} 29 | } 30 | a!(..); 31 | 32 | let [..]: &[u8]; 33 | let [..]: &[u8]; 34 | let (..): (u8,); 35 | let (..): (u8,); 36 | 37 | let (1, (Some(1), 2..=3)) = (1, (None, 2)); 38 | fn func((1, (Some(1), 2..=3)): (isize, (Option, isize))) {} 39 | fn fun([a, ref mut b, ref xs @ .., ref c, d]: [X; 6]) {} 40 | fn foo(a @ [b, mid @ .., c]: [C; 3]) {} 41 | 42 | let [..] = s; 43 | let [..] = s0; 44 | let [..] = s1; 45 | let [..] = s2; 46 | let [_, ..] = s1; 47 | let [.., _] = s1; 48 | let [_, ..] = s2; 49 | let [.., _] = s2; 50 | let [_, _, ..] = s2; 51 | let [_, .., _] = s2; 52 | let [.., _, _] = s2; 53 | let Box { 0: _, .. }: Box<()>; 54 | let Box { 1: _, .. }: Box<()>; 55 | 56 | let [ref _x0, _x1, _, mut _x3, .., ref _x6, _x7] = arr; 57 | let [ref _x0, ..] = arr; 58 | let [_x0, ..] = arr; 59 | let (.., ref mut _x3) = tup; 60 | let a @ [b, .., c] = [C, mk_c(), C]; 61 | let a @ [b, mid @ .., c] = [C, mk_c(), C]; 62 | } 63 | 64 | // source: "../../../ext/jinx-rust/tests/samples/patterns/rest.rs" -------------------------------------------------------------------------------- /tests/output-ext/specifiers/extern.f.rs: -------------------------------------------------------------------------------- 1 | type funky_func = extern "C" fn( 2 | unsafe extern "rust-call" fn( 3 | *const JSJitInfo, 4 | *mut JSContext, 5 | HandleObject, 6 | *mut libc::c_void, 7 | u32, 8 | *mut JSVal 9 | ) -> u8 10 | ); 11 | extern "C" fn sup() {} 12 | extern "C" { 13 | fn some_fn() -> (); 14 | } 15 | extern { 16 | fn quux() -> (); // Post comment 17 | fn syscall( 18 | number: libc::c_long /* comment 1 */, 19 | /* comm 2 */ ... /* sup? */ 20 | ) -> libc::c_long; 21 | unsafe fn foo() -> *mut Bar; 22 | pub(super) const fn foo() -> *mut Bar; 23 | pub(crate) unsafe fn foo() -> *mut Bar; 24 | } 25 | 26 | // source: "../../../ext/jinx-rust/tests/samples/specifiers/extern.rs" -------------------------------------------------------------------------------- /tests/output-ext/specifiers/pub.f.rs: -------------------------------------------------------------------------------- 1 | enum E { 2 | pub U, 3 | pub(crate) T(u8), 4 | pub(super) T { 5 | f: String, 6 | }, 7 | } 8 | pub impl Tr for S { 9 | pub fn f() {} 10 | pub const C: u8 = 0; 11 | pub type T = u8; 12 | pub(in foo) fn f(&self) -> i32 { 13 | 0 14 | } 15 | } 16 | pub struct Pub(Priv2); 17 | mod bar { 18 | pub use *; 19 | } 20 | pub trait Sized {} 21 | const MAIN: u8 = { 22 | pub trait Tr { 23 | fn f(); 24 | const C: u8; 25 | type T; 26 | } 27 | pub struct S { 28 | pub a: u8, 29 | } 30 | struct Ts(pub u8); 31 | pub impl Tr for S { 32 | pub fn f() {} 33 | pub const C: u8 = 0; 34 | pub type T = u8; 35 | } 36 | pub impl S { 37 | pub fn f() {} 38 | pub const C: u8 = 0; 39 | // pub type T = u8; 40 | } 41 | pub extern "C" { 42 | pub fn f(); 43 | pub static St: u8; 44 | } 45 | () 46 | }; 47 | pub(super) fn f(_: Priv) {} 48 | pub(crate) fn g(_: Priv) {} 49 | crate fn h(_: Priv) {} 50 | pub(crate) struct S1; 51 | pub(super) struct S2; 52 | pub(self) struct S3; 53 | pub(in ::core) struct S4; 54 | pub(in a::b) struct S5; 55 | pub type A; 56 | pub static b: Q; 57 | pub extern crate core; 58 | struct Bar(pub ()); 59 | pub struct C(pub isize, isize); 60 | pub struct D(pub isize); 61 | pub struct bool; 62 | pub struct Pub(pub T); 63 | pub type A; 64 | pub mod bar { 65 | pub use a::b::c; 66 | pub mod b {} 67 | pub struct S { 68 | pub(in foo) x: i32, 69 | } 70 | } 71 | pub macro m() {} 72 | pub(in Self::f) struct Z; 73 | pub extern crate self as name; 74 | pub use name::name as bug; 75 | 76 | // source: "../../../ext/jinx-rust/tests/samples/specifiers/pub.rs" -------------------------------------------------------------------------------- /tests/output-ext/statements/const.f.rs: -------------------------------------------------------------------------------- 1 | const X: u8; 2 | const B; 3 | const A: u8; 4 | pub const A: Self::AssocTy = 1; 5 | const FOO: dyn Fn() -> _ = ""; 6 | pub const FOO: &'static *const i32 = &(&0 as _); 7 | const TEST: fn() -> _ = 1; 8 | const MY_A: A = A { 9 | e: |s, a, b| { 10 | if s { 11 | let _ = (); 12 | } else if let Q(s) = b.r(|p| p.d()) { 13 | let _ = (); 14 | } 15 | }, 16 | }; 17 | 18 | // source: "../../../ext/jinx-rust/tests/samples/statements/const.rs" -------------------------------------------------------------------------------- /tests/output-ext/statements/enum.f.rs: -------------------------------------------------------------------------------- 1 | enum E {} 2 | 3 | enum E { 4 | Foo { 5 | limb_with_align16: Align16, 6 | }, 7 | Bar, 8 | } 9 | enum E { 10 | Foo { 11 | foo: u32, 12 | }, 13 | Bar { 14 | bar: u32, 15 | }, 16 | } 17 | 18 | enum A { 19 | Ok = u8::MAX - 1, 20 | Ok2 = -1, 21 | OhNo = u8::MIN, 22 | Bi64 = 0x8000_0000, 23 | orange = 8 >> 1, 24 | } 25 | enum A { 26 | union, 27 | } 28 | enum B { 29 | union {}, 30 | } 31 | enum C { 32 | union(), 33 | } 34 | 35 | enum E { 36 | A = { 37 | enum F { 38 | B, 39 | } 40 | 0 41 | }, 42 | } 43 | enum E { 44 | _None, 45 | _Some(T), 46 | } 47 | enum E { 48 | EM(W), 49 | EM { 50 | x: X, 51 | }, 52 | EM(isize, Y), 53 | EM { 54 | u: isize, 55 | x: Z, 56 | }, 57 | EM([u8]), 58 | EM { 59 | x: str, 60 | }, 61 | EM(isize, [f32]), 62 | EM { 63 | u: isize, 64 | x: [u32], 65 | }, 66 | EM(Path1), 67 | EM { 68 | x: Path2, 69 | }, 70 | EM(isize, Path3), 71 | EM { 72 | u: isize, 73 | x: Path4, 74 | }, 75 | EM(dyn Foo), 76 | EM { 77 | x: dyn Bar, 78 | }, 79 | EM(isize, dyn FooBar), 80 | EM { 81 | u: isize, 82 | x: dyn BarFoo, 83 | }, 84 | EM(<&'static [i8] as Deref>::Target), 85 | EM { 86 | x: <&'static [char] as Deref>::Target, 87 | }, 88 | EM(isize, <&'static [f64] as Deref>::Target), 89 | EM { 90 | u: isize, 91 | x: <&'static [i32] as Deref>::Target, 92 | }, 93 | } 94 | enum E<'a, 'b, 'c: 'b> { 95 | A(extern "Rust" fn(&'a isize)), 96 | B(&'b [isize]), 97 | C(&'b mut &'c str), 98 | } 99 | 100 | pub enum X where D: Copy + Debug + Eq {} 101 | 102 | // source: "../../../ext/jinx-rust/tests/samples/statements/enum.rs" -------------------------------------------------------------------------------- /tests/output-ext/statements/impl.f.rs: -------------------------------------------------------------------------------- 1 | impl X {} 2 | impl X { 3 | fn f(); 4 | fn f() {} 5 | type Y; 6 | type Z: Ord; 7 | type W: Ord where Self: Eq; 8 | type W where Self: Eq; 9 | fn foo() { 10 | struct S; 11 | impl S { 12 | pub const X: u8 = 0; 13 | pub const fn bar() {} 14 | async fn qux() {} 15 | } 16 | } 17 | } 18 | impl X for () {} 19 | impl X for Y {} 20 | impl ! {} 21 | impl ! where u8: A {} 22 | impl ! where u8: A {} 23 | impl !Send for A {} 24 | impl <*const u8>::C {} 25 | impl ::C {} 26 | impl ::C {} 27 | impl <::B>::C {} 28 | impl<'a, I, T: 'a, E> Iterator 29 | for Y<'a, I, E> 30 | where I: Iterator {} 31 | impl S for E {} 32 | unsafe impl A for isize {} 33 | unsafe impl Send for A {} 34 | unsafe impl Sync for A {} 35 | impl<'a> A for &'a [isize] {} 36 | impl ::A::B for ::C {} 37 | impl ::A for () {} 38 | impl ::A {} 39 | impl A for [B; 1] {} 40 | impl A for (::D, E) {} 41 | impl ::A for [B; 0] {} 42 | impl<'a> A for &'a [isize] {} 43 | impl<'a> dyn T + 'a {} 44 | impl<'a> dyn T + 'a {} 45 | impl<'a> dyn ::Foo::Trait + 'a {} 46 | impl A for T {} 47 | impl<'a, 'b, 'c> S for &'a &'b &'c Q {} 48 | impl Foo for F {} 49 | impl A for T where for<'a> T: B<'a> {} 50 | impl<'a, T, const N: usize> IntoIterator for &'a Table {} 51 | impl A for (B,) {} 52 | impl !A for (B,) {} 53 | impl A for Box {} 54 | impl A for lib::Something {} 55 | impl A for D {} 56 | impl A {} 57 | 58 | // source: "../../../ext/jinx-rust/tests/samples/statements/impl.rs" -------------------------------------------------------------------------------- /tests/output-ext/statements/self.f.rs: -------------------------------------------------------------------------------- 1 | fn f(self) {} 2 | fn f(&self) {} 3 | fn f(mut self) {} 4 | fn f(&mut self) {} 5 | fn f(&'a self) {} 6 | fn f(&'a mut self) {} 7 | fn f(self: u8) {} 8 | fn f(mut self: u8) {} 9 | type X = fn(self); 10 | type X = fn(&self); 11 | // type X = fn(mut self); 12 | type X = fn(&mut self); 13 | type X = fn(&'a self); 14 | type X = fn(&'a mut self); 15 | type X = fn(self: u8); 16 | // type X = fn(mut self: u8); 17 | async fn foo<'b>(self: &'b Foo<'a>) -> &() { 18 | self.0 19 | } 20 | fn f<'b>(self: &'b Foo<'a>) -> &() { 21 | self.0 22 | } 23 | fn f<'a>(self: &Alias, arg: &'a ()) -> &() { 24 | arg 25 | } 26 | fn f(&mut self) -> u32; 27 | fn f(mut self: Box); 28 | fn f(self: _) {} 29 | fn f(self: &_) {} 30 | fn f(&self) -> Self; 31 | // fn f(self::S: S) {} 32 | // fn g(&self::S: &S) {} 33 | // fn h(&mut self::S: &mut S) {} 34 | 35 | // source: "../../../ext/jinx-rust/tests/samples/statements/self.rs" -------------------------------------------------------------------------------- /tests/output-ext/statements/spread.f.rs: -------------------------------------------------------------------------------- 1 | fn main() {} 2 | fn f1_1(x: isize, ...) {} 3 | fn f1_2(...) {} 4 | extern "C" fn f2_1(x: isize, ...) {} 5 | extern "C" fn f2_2(...) {} 6 | extern "C" fn f2_3(..., x: isize) {} 7 | extern fn f3_1(x: isize, ...) {} 8 | extern fn f3_2(...) {} 9 | extern fn f3_3(..., x: isize) {} 10 | extern { 11 | fn e_f1(...); 12 | fn e_f2(..., x: isize); 13 | } 14 | struct X; 15 | impl X { 16 | fn i_f1(x: isize, ...) {} 17 | fn i_f2(...) {} 18 | fn i_f3(..., x: isize, ...) {} 19 | fn i_f4(..., x: isize, ...) {} 20 | } 21 | trait T { 22 | fn t_f1(x: isize, ...) {} 23 | fn t_f2(x: isize, ...); 24 | fn t_f3(...) {} 25 | fn t_f4(...); 26 | fn t_f5(..., x: isize) {} 27 | fn t_f6(..., x: isize); 28 | } 29 | 30 | extern "C" { 31 | pub fn foo(x: i32, ...); 32 | } 33 | 34 | // source: "../../../ext/jinx-rust/tests/samples/statements/spread.rs" -------------------------------------------------------------------------------- /tests/output-ext/statements/statements.f.rs: -------------------------------------------------------------------------------- 1 | const _: () = { 2 | pub trait A { 3 | const _: () = (); 4 | } 5 | impl A for () { 6 | const _: () = (); 7 | } 8 | impl dyn A { 9 | const _: () = (); 10 | } 11 | }; 12 | 13 | extern r#"C"# { 14 | fn bar(); 15 | } 16 | extern r#"C"# fn foo() {} 17 | type T = extern r#"C"# fn(); 18 | extern "\x43" fn foo() {} 19 | extern "\x43" { 20 | fn bar(); 21 | } 22 | type T = extern "\x43" fn(); 23 | 24 | // extern crate async; 25 | // extern crate async as something_else; 26 | 27 | fn f1(); 28 | fn f2() {} 29 | fn f3(); 30 | 31 | trait X { 32 | fn f(); 33 | fn f() {} 34 | const Y: u8; 35 | } 36 | 37 | extern "C" { 38 | fn f(); 39 | fn f(); 40 | static X: u8; 41 | static mut Y: u8; 42 | // type E: where; 43 | type A: Ord; 44 | type A<'a> where 'a: 'static; 45 | type A where T: 'static; 46 | type A = u8; 47 | type A<'a: 'static, T: Ord + 'static> 48 | : Eq + PartialEq 49 | where T: 'static + Copy = Vec; 50 | } 51 | const async fn test() {} 52 | async unsafe fn test() {} 53 | const unsafe fn test() {} 54 | unsafe extern fn test() {} 55 | fn f() { 56 | async fn f(); 57 | unsafe fn f(); 58 | const fn f(); 59 | extern "C" fn f(); 60 | const async unsafe extern "C" fn f(); 61 | } 62 | const fn f(a: *const i32, b: i32) -> bool {} 63 | unsafe fn f(&self) -> u32; 64 | const unsafe fn f(v: u32) -> u32 {} 65 | unsafe fn f(func: unsafe fn() -> ()) -> () {} 66 | struct Range< 67 | const FROM: usize = 0, 68 | const LEN: usize = 0, 69 | const TO: usize = FROM 70 | >; 71 | impl From<[u8; 1 + 1]> for Foo {} 72 | fn f(d: [u8; 1 + 1]) -> A 73 | where [u8; 1 + 1]: From<[u8; 1 + 1]> {} 74 | fn f<'a, 'b, 'c, T>(x: foo::X<'a, T, 'b, 'c>) {} 75 | fn f() -> Option Option> { 76 | Some(|| Some(true)) 77 | } 78 | fn a() { 79 | let a = 0; 80 | let _b = 0; 81 | let _ = 0; 82 | let mut b = 0; 83 | let mut _b = 0; 84 | } 85 | 86 | enum Test3 { 87 | Var1, 88 | Var2(String), 89 | StillFine { 90 | def: i32, 91 | }, 92 | } 93 | enum E { 94 | UnitVariant, 95 | TupleVariant(), 96 | BracedVariant {}, 97 | T(T, [!; 0]), 98 | #[allow(dead_code)] U(U), 99 | } 100 | fn foobar() -> usize where (): Foobar {} 101 | 102 | mod a { 103 | extern "C" { 104 | pub fn free(x: *const u8); 105 | } 106 | } 107 | pub union U { 108 | pub a: u8, 109 | pub(super) b: u8, 110 | c: u8, 111 | } 112 | 113 | trait C { 114 | fn D(&self, f: F) where F: FnMut(A) -> Q; 115 | } 116 | trait A {} 117 | trait A: B::C {} 118 | trait A: B::C {} 119 | fn f() -> () {} 120 | fn f = i32>>() {} 121 | fn f(mut f: F) where F: FnMut(&mut R, bool) {} 122 | fn f(f: F) where F: for<'a> Fn(&'a isize, &'a isize) -> isize {} 123 | fn f(f: F) -> isize where F: Fn() -> isize { 124 | f() 125 | } 126 | async fn g(((ref a, ref mut b), (ref mut c, ref d)): ((A, A), (A, A))) {} 127 | pub unsafe extern "C" fn bar(_: i32, mut ap: ...) -> usize {} 128 | unsafe fn f(&self, x: &usize) { 129 | *self + *x; 130 | } 131 | fn f() {} 132 | fn f F<(&'a A,)>>(_: F) {} 133 | fn f(a: M) where M: A, M::B: C {} 134 | fn f(t: fn(&A)) where fn(&A): for<'a> F<(&'a A,)> {} 135 | #[no_mangle] 136 | pub extern "C" fn rust_no_mangle() -> i32 {} 137 | pub fn foo<'a, 'b>(x: Foo<'a, 'b>, _o: Option<&&()>) { 138 | let _y = x.foo; 139 | } 140 | const x: &'static dyn Fn() = &(|| e!("q")); 141 | const fn foo() -> i32 {} 142 | extern "\x43" fn foo() {} 143 | 144 | extern "\x43" { 145 | fn bar(); 146 | } 147 | 148 | type T = extern "\x43" fn(); 149 | extern r#"C"# fn foo() {} 150 | 151 | extern r#"C"# { 152 | fn bar(); 153 | } 154 | 155 | type T = extern r#"C"# fn(); 156 | 157 | // source: "../../../ext/jinx-rust/tests/samples/statements/statements.rs" -------------------------------------------------------------------------------- /tests/output-ext/statements/static.f.rs: -------------------------------------------------------------------------------- 1 | static A: u8; 2 | static B; 3 | 4 | static mut C: u8; 5 | static mut D; 6 | static X: u8; 7 | pub static B: &'static a = unsafe { &q }; 8 | static A: fn(_) -> u8 = |_| 8; 9 | static BOO: dyn Fn() -> _ = ""; 10 | static x: _; 11 | 12 | // source: "../../../ext/jinx-rust/tests/samples/statements/static.rs" -------------------------------------------------------------------------------- /tests/output-ext/statements/struct.f.rs: -------------------------------------------------------------------------------- 1 | struct S Q, B: 'a + Q, C: 'a, G: Q + 'a, H: Q, I:>; 2 | struct Empty1 {} 3 | struct Empty2; 4 | struct Empty7(); 5 | struct Align8Many { 6 | a: i32, 7 | b: i32, 8 | c: i32, 9 | d: u8, 10 | } 11 | struct A([T]); 12 | struct A(T); 13 | struct cat { 14 | done: extern "C" fn(usize), 15 | meows: usize, 16 | } 17 | struct Test3<'a, 'b, 'c> { 18 | x: extern "Rust" fn(&'a isize), 19 | y: extern "Rust" fn(&'b [isize]), 20 | c: extern "Rust" fn(&'c str), 21 | a: fn(u32) -> u32, 22 | b: extern "C" fn(u32) -> u32, 23 | c: unsafe fn(u32) -> u32, 24 | d: unsafe extern "C" fn(u32) -> u32, 25 | } 26 | struct Test4<'a, 'b: 'a> { 27 | x: &'a mut &'b isize, 28 | } 29 | struct Test6<'a, 'b: 'a> { 30 | x: &'a mut extern "Rust" fn(&'b isize), 31 | } 32 | struct Foo<'a> { 33 | x: Box &'a i32) + 'static>, 34 | } 35 | struct X; 36 | struct U {} 37 | struct P(T); 38 | struct A where U: E(U); 39 | struct A where U: E(U) -> R; 40 | struct A(U) where U: Eq; 41 | struct K<'a>(&'a ()); 42 | pub struct A([u8; 1]); 43 | pub(crate) struct S<'a, I, E>(I, &'a E); 44 | pub struct A(C); 45 | pub struct A(T); 46 | pub struct Table([Option; N]); 47 | struct B; 48 | struct A(C, ()); 49 | struct A(B) where B: Marker; 50 | struct A(T, U) where B: Marker; 51 | struct A<'a, S: B<'a> = i32>(S, &'a ()); 52 | struct S1(pub(in foo) (), pub T, pub(crate) (), pub ((), T)); 53 | struct G(*const T, *const U); 54 | pub struct Unique { 55 | s: *const T, 56 | } 57 | unsafe impl Send for Unique {} 58 | pub struct A(u32, ::b::Q); 59 | struct S(>::AS); 60 | pub struct A where I: B { 61 | w: ::G, 62 | } 63 | 64 | // source: "../../../ext/jinx-rust/tests/samples/statements/struct.rs" -------------------------------------------------------------------------------- /tests/output-ext/statements/trait.f.rs: -------------------------------------------------------------------------------- 1 | trait A {} 2 | trait A {} 3 | trait T2<'x, 'y>: T1<'x> {} 4 | trait T = S where >::T: H; 5 | trait A: B + E<()> {} 6 | trait A>: D {} 7 | trait A = B; 8 | trait A = B where T: C; 9 | trait A: B + C {} 10 | trait A = std::fmt::Display + std::fmt::Debug; 11 | trait B = std::fmt::Display + std::fmt::Debug; 12 | trait A = Default; 13 | trait A = B; 14 | trait A = B; 15 | trait A<'a, T: 'a> = B<&'a D>; 16 | trait A = 'static; 17 | trait A = D + E where F<(G, H)>: I; 18 | trait A = where D: F; 19 | trait A: T2 {} 20 | trait A {} 21 | trait A {} 22 | trait A {} 23 | trait A {} 24 | trait A {} 25 | trait A {} 26 | 27 | pub trait A {} 28 | pub trait C = A + B; 29 | pub trait A: Sized {} 30 | 31 | // source: "../../../ext/jinx-rust/tests/samples/statements/trait.rs" -------------------------------------------------------------------------------- /tests/output-ext/statements/union.f.rs: -------------------------------------------------------------------------------- 1 | union {}; 2 | union::b {}; 3 | union union<'union> { 4 | union: &'union union<'union>, 5 | } 6 | struct union; 7 | 8 | impl union { 9 | pub fn new() -> Self { 10 | union {} 11 | } 12 | } 13 | 14 | fn main() { 15 | let _u = union::new(); 16 | let mut r#async = 1; 17 | union as T; 18 | } 19 | 20 | // source: "../../../ext/jinx-rust/tests/samples/statements/union.rs" -------------------------------------------------------------------------------- /tests/output-ext/statements/use.f.rs: -------------------------------------------------------------------------------- 1 | pub use self::bb::{ aa, bb }; 2 | pub use self::cc::*; 3 | use Self::f; 4 | use ::super::{ S, Z }; 5 | use ::super::main; 6 | use a::*; 7 | use m::S; 8 | use ::{ ::{}, ::{} }; 9 | extern crate x; 10 | use std::mem::self; 11 | use foo::bar::self as abc; 12 | extern crate priv_impl_prim_ty as bar; 13 | extern crate crate_method_reexport_grrrrrrr2; 14 | use std::io::{ self, Error as IoError }; 15 | use std::net::{ self as stdnet, TcpStream }; 16 | use foo::{ Foo, bar::{ baz::{}, foobar::* }, * }; 17 | use foo::bar::baz::{ *, * }; 18 | use foo::{}; 19 | mod m { 20 | use S; 21 | use self::{ self }; 22 | use super::{ self }; 23 | } 24 | pub use ::E::*; 25 | use crate as _; 26 | pub use ::E::V::{ self }; 27 | use std::{ ops::A, marker::{ C, B } }; 28 | mod bar { 29 | pub use bar::*; 30 | pub use main as f; 31 | pub use super::*; 32 | use ::std::mem; 33 | use crate_method_reexport_grrrrrrr2::rust::add; 34 | crate struct Foo; 35 | } 36 | use rustc_hir::BinOpKind::{ 37 | Add, 38 | And, 39 | BitAnd, 40 | BitOr, 41 | BitXor, 42 | Div, 43 | Eq, 44 | Ge, 45 | Gtab, 46 | }; 47 | use rustc_ast::ast::{ 48 | ItemForeignMod, 49 | ItemImpl, 50 | ItemMac, 51 | ItemMod, 52 | ItemStatic, 53 | ItemDefaultImpl, 54 | }; 55 | use exceedingly::looooooooooooooooooooooooooooooooooooooooooooooooooooooooooong::import::path::{ 56 | ItemA, 57 | ItemB, 58 | }; 59 | use exceedingly::loooooooooooooooooooooooooooooooooooooooooooooooooooooooong::import::path::{ 60 | ItemA, 61 | ItemB, 62 | }; 63 | 64 | use list::{ 65 | // Some item 66 | SomeItem /* Comment */, 67 | /* Another item */ AnotherItem /* Another Comment */, // Last Item 68 | LastItem, 69 | }; 70 | 71 | use test::{ Other /* C */, /* A */ self /* B */ }; 72 | 73 | use rustc_ast::{ self }; 74 | use ::{ /* Pre-comment! */ Foo, Bar /* comment */ }; 75 | use Foo::{ Bar, Baz }; 76 | pub use rustc_ast::ast::{ 77 | Expr_, 78 | Expr, 79 | ExprAssign, 80 | ExprCall, 81 | ExprMethodCall, 82 | ExprPath, 83 | }; 84 | 85 | use rustc_ast::some::{}; 86 | 87 | use self; 88 | use std::io::{ self }; 89 | use std::io::self; 90 | 91 | mod Foo { 92 | pub use rustc_ast::ast::{ A }; 93 | mod Foo2 { 94 | pub use rustc_ast::ast::{ A, self, B }; 95 | } 96 | } 97 | 98 | fn test() { 99 | use Baz::*; 100 | use Qux; 101 | } 102 | use foo::bar::baz as baz; 103 | use bar::quux as kaas; 104 | use foo; 105 | use foo::{ self as bar, baz }; 106 | use foo::{ self as bar }; 107 | use foo::{ qux as bar }; 108 | use foo::{ baz, qux as bar }; 109 | use ::foo; 110 | use ::foo::{ Bar }; 111 | use ::foo::{ Bar, Baz }; 112 | use ::{ Foo }; 113 | use ::{ Bar, Baz }; 114 | use *; 115 | use *; 116 | error; 117 | use super::*; 118 | use foo::issue_1356::*; 119 | #[cfg(unix)] 120 | use self::unix::{}; 121 | use foo::{ 122 | a, 123 | bar::{ 124 | baz, 125 | qux, 126 | xxxxxxxxxxx, 127 | yyyyyyyyyyyyy, 128 | zzzzzzzzzzzzzzzz, 129 | foo::{ a, b, cxxxxxxxxxxxxx, yyyyyyyyyyyyyy, zzzzzzzzzzzzzzzz }, 130 | }, 131 | b, 132 | boo, 133 | c, 134 | }; 135 | use fooo::{ 136 | baar::{ 137 | foobar::{ 138 | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, 139 | yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy, 140 | zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz, 141 | }, 142 | }, 143 | z, 144 | bar, 145 | bar::*, 146 | x, 147 | y, 148 | }; 149 | use exonum::{ 150 | api::{ Api, ApiError }, 151 | blockchain::{ self, BlockProof, Blockchain, Transaction, TransactionSet }, 152 | crypto::{ Hash, PublicKey }, 153 | helpers::Height, 154 | node::TransactionSend, 155 | storage::{ ListProof, MapProof }, 156 | }; 157 | use a::{ b::{ c::* } }; 158 | use a::{ b::{ c::{} } }; 159 | use a::{ b::{ c::d } }; 160 | use a::{ b::{ c::{ xxx, yyy, zzz } } }; 161 | /// a 162 | // b 163 | use c; 164 | #[macro_use] 165 | use imports_with_attr; 166 | use std::f64::consts::{ SQRT_2, E, PI }; 167 | #[rustfmt::skip] 168 | use std::fmt::{self, {Display, Formatter}}; 169 | 170 | // source: "../../../ext/jinx-rust/tests/samples/statements/use.rs" -------------------------------------------------------------------------------- /tests/output-ext/types/cast.f.rs: -------------------------------------------------------------------------------- 1 | fn a() { 2 | if (5u64 as i32 as u16) == 0u16 { 3 | } 4 | [ 5 | (u64 as u8 as i8) == 9i8, 6 | &[1, 2, 3] as *const _ as *const [i32; 3], 7 | -0i16 as i8, 8 | !0u16 as u8, 9 | (0u16 << 15) as u8, 10 | (0u32 << 31) as u16, 11 | Foo::Bar as i8, 12 | 0 as i32 as i32, 13 | // 0 as i32: i32, 14 | // 0i32: i32 as i32, 15 | // 0i32: i32: i32 as u32 as i32, 16 | // 0i32: i32: i32, 17 | 0u8 as u32, 18 | a as fn(u8), 19 | // ::Assoc<3>, 20 | drop as fn(u8), 21 | &x as *const _, 22 | Box::new(A) as &dyn B, 23 | box (move |y: i32| -> i32 { x + y }) as Box< 24 | dyn (FnMut(i32) -> i32) + 'static 25 | >, 26 | &x as *const i16 as f32, 27 | &(|_| ()) as &dyn for<'x> Fn(>::V), 28 | TestStruct { x: 0x1234 as *const [isize; 2] }, 29 | !(FOO as *const usize).a(), 30 | !(42 as *const usize).a(), 31 | (0 as *const usize).a(), 32 | !("foo" as *const str).a(), 33 | (&x as T)[0], 34 | ] 35 | } 36 | const A: *const u8 = &0 as *const _ as *const Q as *const u8; 37 | 38 | // source: "../../../ext/jinx-rust/tests/samples/types/cast.rs" -------------------------------------------------------------------------------- /tests/output-ext/types/never.f.rs: -------------------------------------------------------------------------------- 1 | fn a() { 2 | a::(); 3 | let x: ! = a!(); 4 | let x: ! = unsafe { a::(C) }; 5 | >::from(never); 6 | } 7 | fn a(x: !) -> ! { 8 | x 9 | } 10 | fn foo(never: !) {} 11 | fn a(x: !) {} 12 | fn a(ref x: !) {} 13 | fn a(x: &[!]) {} 14 | fn a(x: B<(), !>) {} 15 | 16 | impl A for B { 17 | fn c(&self, d: &!) -> E {} 18 | } 19 | impl A for ! {} 20 | type A = !; 21 | 22 | // source: "../../../ext/jinx-rust/tests/samples/types/never.rs" -------------------------------------------------------------------------------- /tests/output/comments/assignment.f.rs: -------------------------------------------------------------------------------- 1 | f1 = | 2 | //comment 3 | a 4 | | {}; 5 | 6 | f2 = | 7 | a //comment 8 | | {}; 9 | 10 | f3 = | 11 | a 12 | //comment 13 | | {}; 14 | 15 | f4 = // Comment 16 | || {}; 17 | 18 | f5 = 19 | // Comment 20 | 21 | || {}; 22 | 23 | f6 = 24 | /* comment */ 25 | 26 | // Comment 27 | 28 | || {}; 29 | 30 | let f4 = // Comment 31 | || {}; 32 | 33 | let f5 = 34 | // Comment 35 | 36 | || {}; 37 | 38 | let f6 = 39 | /* comment */ 40 | 41 | // Comment 42 | 43 | || {}; 44 | 45 | const kochabCooieGameOnOboleUnweave = // ??? 46 | annularCooeedSplicesWalksWayWay; 47 | 48 | const bifornCringerMoshedPerplexSawder = // !!! 49 | glimseGlyphsHazardNoopsTieTie + 50 | averredBathersBoxroomBuggyNurl - 51 | anodyneCondosMalateOverateRetinol; 52 | 53 | fnNumber = 54 | // Comment 55 | 3; 56 | 57 | fnNumber = 58 | // Comment 59 | 60 | 3; 61 | 62 | fnNumber = 63 | // Comment0 64 | // Comment1 65 | 3; 66 | 67 | fnNumber = /* comment */ 3; 68 | 69 | fnNumber = 70 | /* comments0 */ 71 | /* comments1 */ 72 | 3; 73 | 74 | fnNumber = 75 | // Comment 76 | 3; 77 | 78 | let fnNumber = 79 | // Comment 80 | 81 | 3; 82 | 83 | let fnNumber = 84 | // Comment0 85 | // Comment1 86 | 3; 87 | 88 | let fnNumber = /* comment */ 3; 89 | 90 | let fnNumber = 91 | /* comments0 */ 92 | /* comments1 */ 93 | 3; 94 | 95 | fnString = 96 | // Comment 97 | "some" + "long" + "string"; 98 | 99 | fnString = 100 | // Comment 101 | 102 | "some" + "long" + "string"; 103 | 104 | fnString = 105 | // Comment 106 | 107 | "some" + "long" + "string"; 108 | 109 | fnString = 110 | /* comment */ 111 | "some" + "long" + "string"; 112 | 113 | fnString = 114 | /** 115 | * multi-line 116 | */ 117 | "some" + "long" + "string"; 118 | 119 | fnString = 120 | /* inline */ "some" + 121 | "long" + 122 | "string" + 123 | "some" + 124 | "long" + 125 | "string" + 126 | "some" + 127 | "long" + 128 | "string" + 129 | "some" + 130 | "long" + 131 | "string"; 132 | 133 | fnString = // Comment0 134 | // Comment1 135 | "some" + "long" + "string"; 136 | 137 | fnString = "some" + "long" + "string"; // Comment 138 | 139 | fnString = 140 | // Comment 141 | "some" + "long" + "string"; 142 | 143 | let fnString = 144 | // Comment 145 | 146 | "some" + "long" + "string"; 147 | 148 | let fnString = 149 | // Comment 150 | 151 | "some" + "long" + "string"; 152 | 153 | let fnString = 154 | /* comment */ 155 | "some" + "long" + "string"; 156 | 157 | let fnString = 158 | /** 159 | * multi-line 160 | */ 161 | "some" + "long" + "string"; 162 | 163 | let fnString = 164 | /* inline */ "some" + 165 | "long" + 166 | "string" + 167 | "some" + 168 | "long" + 169 | "string" + 170 | "some" + 171 | "long" + 172 | "string" + 173 | "some" + 174 | "long" + 175 | "string"; 176 | 177 | let fnString = // Comment0 178 | // Comment1 179 | "some" + "long" + "string"; 180 | 181 | let fnString = "some" + "long" + "string"; // Comment 182 | 183 | let obj1 = 184 | // 36_______ 185 | A { 186 | key: "val", 187 | }; 188 | 189 | let obj2 = 190 | // 37_______ 191 | A { 192 | key: "val", 193 | }; 194 | 195 | let obj3 = A { // 38_______ 196 | key: "val", 197 | }; 198 | 199 | let obj4 = A { 200 | // 39_______ 201 | key: "val", 202 | }; 203 | 204 | let obj5 = 205 | // 40_______ 206 | ["val"]; 207 | 208 | let obj6 = 209 | // 41_______ 210 | ["val"]; 211 | 212 | let obj7 = [ 213 | // 42_______ 214 | "val", 215 | ]; 216 | 217 | let obj8 = [ 218 | // 43_______ 219 | "val", 220 | ]; 221 | 222 | const A { a /* 0_______ */: 1 } = b; 223 | 224 | const A { c: 1 /* 1_______ */ } = d; 225 | 226 | let A { 227 | d: b, //2_______ 228 | } = c; 229 | 230 | const foo = A { 231 | a: "a" /* 3_______________ */, 232 | 233 | /* 4_________ */ 234 | b: "b", 235 | }; 236 | 237 | let // 44_______ 238 | foo1 = "val"; 239 | 240 | const foo3 = 123; 241 | // 45_______ 242 | ["2", "3"].forEach(|x| console.log(x)); 243 | 244 | let a = b || /** 46_______ */ c; 245 | 246 | let a = A { 247 | a /* 47_______ */: || 1, 248 | }; 249 | 250 | let a = /* 48 */ 0; 251 | 252 | let b = /* 253 | * 4 254 | * 9 255 | */ 0; 256 | 257 | let c = /* 258 | * 5 259 | * 0 260 | */ 0; 261 | 262 | let d = /* 263 | * 5 264 | 265 | * 1 266 | */ 0; 267 | 268 | fn foo() { 269 | let x = foo.bar???.baz; // comment 270 | let x = 271 | // comment 272 | foo.bar???.baz; 273 | let x = 274 | // comment 275 | foo.bar???.baz; // comment 276 | let x = foo.bar???????????????.baz; // comment 277 | // comment 278 | // comment 279 | // comment 280 | // comment 281 | let x = /* Invisible comment */ try { foo()? }; 282 | let loooooooooooooooooooooooooooooooooooooooooong = 283 | does_this?.look?.good?.should_we_break?.after_the_first_question_mark?; 284 | 285 | let x = y.z; // comment 286 | 287 | self.rev_dep_graph 288 | .iter() 289 | // Remove nodes that are not dirty 290 | .filter(|&(unit, _)| dirties.contains(&unit)) 291 | // Retain only dirty dependencies of the ones that are dirty 292 | .map(|(k, deps)| { 293 | ( 294 | k.clone(), 295 | deps 296 | .iter() 297 | .cloned() 298 | .filter(|d| dirties.contains(&d)) 299 | .collect(), 300 | ) 301 | }); 302 | 303 | let y = expr /* comment */ 304 | .kaas()?; 305 | 306 | (Foo { 307 | // comment 308 | ..a 309 | } = a); 310 | } 311 | 312 | // source: "../../samples/comments/assignment.rs" -------------------------------------------------------------------------------- /tests/output/comments/binaryish.f.rs: -------------------------------------------------------------------------------- 1 | a = b || /** 5_______ */ c; 2 | 3 | a = b || /** 6_______ */ c; 4 | 5 | a = 6 | b || 7 | /** 7_____________________________________________________________________________ */ 8 | c; 9 | 10 | a = 11 | b || 12 | /** 8_____________________________________________________________________________ */ c; 13 | 14 | a = 15 | b || 16 | /** 9_____________________________________________________________________________ */ c; 17 | 18 | a = b && /** 10_______ */ c; 19 | 20 | a = b && /** 11_______ */ c; 21 | 22 | a = 23 | b && 24 | /** 12_____________________________________________________________________________ */ 25 | c; 26 | 27 | a = 28 | b && 29 | /** 13_____________________________________________________________________________ */ c; 30 | 31 | a = 32 | b && 33 | /** 14_____________________________________________________________________________ */ c; 34 | 35 | a = b + /** 15_______ */ c; 36 | 37 | a = b + /** 16_______ */ c; 38 | 39 | a = 40 | b + 41 | /** 17_____________________________________________________________________________ */ 42 | c; 43 | 44 | a = 45 | b + 46 | /** 18_____________________________________________________________________________ */ c; 47 | 48 | a = 49 | b + 50 | /** 19_____________________________________________________________________________ */ c; 51 | 52 | a = 53 | b || // 20_______ 54 | c; 55 | 56 | a = 57 | b || // 21_____________________________________________________________________________ 58 | c; 59 | 60 | a = 61 | b && // 22_______ 62 | c; 63 | 64 | a = 65 | b && // 23_____________________________________________________________________________ 66 | c; 67 | 68 | a = 69 | b + // 24_______ 70 | c; 71 | 72 | a = 73 | b + // 25_____________________________________________________________________________ 74 | c; 75 | 76 | 0 + 77 | // 26_______ 78 | x; 79 | 80 | 0 * 81 | // 27_______ 82 | x; 83 | 0 / 84 | // 28_______ 85 | x; 86 | 0 - 87 | // 29_______ 88 | x; 89 | 0 % 90 | // 30_______ 91 | x; 92 | 0 << 93 | // 31_______ 94 | x; 95 | 0 >> 96 | // 32_______ 97 | x; 98 | 0 & 99 | // 33_______ 100 | x; 101 | 0 | 102 | // 34_______ 103 | x; 104 | 0 ^ 105 | // 35_______ 106 | x; 107 | 108 | // source: "../../samples/comments/binaryish.rs" -------------------------------------------------------------------------------- /tests/output/comments/blocks.f.rs: -------------------------------------------------------------------------------- 1 | if 0 { 2 | 0; 3 | // 4 | } else if 0 { 5 | } 6 | 7 | if 1 { 8 | /* 9 | * _______ 10 | */ 11 | } 12 | 13 | if 1 { 14 | // _______ 15 | } 16 | 17 | if 1 { 18 | } else { 19 | // _______ 20 | } 21 | 22 | if 23 | 1 24 | // if 1 (ln trailing) 25 | { 26 | 1; 27 | } else if 28 | // else if 2 (leading) 29 | 2 30 | { 31 | 2; 32 | } else if 33 | // else if 3 (leading) 34 | // else if 3 (leading) 35 | // else if 3 (leading) 36 | 3 37 | // if 3 (ln trailing) 38 | { 39 | 3; 40 | } else if 41 | // else if 4 (leading) 42 | 4 43 | { 44 | // 4 body 45 | } else { 46 | // else (leading) 47 | } 48 | 49 | if 50 | 5 // if 5 (trailing) 51 | { 52 | 1; 53 | } 54 | 55 | if 56 | 6 // if 6 (trailing) 57 | { 58 | 6; 59 | } else if 60 | 7 // else if 7 (trailing) 61 | { 62 | 7; 63 | } else { 64 | // else (trailing) 65 | 0; 66 | } 67 | 68 | if 69 | 8 // if 8 (trailing) 70 | // ^ if 8 (ln trailing) 71 | { 72 | 1; 73 | } else if 74 | 9 // else if 9 75 | // else if 9 (ln trailing) 76 | { 77 | 1; 78 | } else { 79 | // else (trailing) 80 | // else (ln trailing) 81 | 1; 82 | } 83 | 84 | if 85 | 10 /* _______ */ // _______ 86 | { 87 | 10; 88 | } else if 11 /* _______ */ { 89 | 11; 90 | } else if 91 | 12 // _______ /* _______ */ // _______ 92 | { 93 | 12; 94 | } else if 95 | 13 /* _______ */ /* _______ */ // _______ 96 | { 97 | 13; 98 | } else { 99 | /* _______ */ 0; 100 | } 101 | 102 | if 103 | 14 // _______ 104 | /* _______ */ 105 | // _______ 106 | { 107 | 14; 108 | } else if 109 | 15 // _______ 110 | /* _______ */ 111 | /* _______ */ // _______ 112 | 113 | { 114 | 15; 115 | } 116 | 117 | for // _______ 118 | a in b { 119 | } 120 | 121 | for /* _______ */ a in b { 122 | } 123 | 124 | let a = {/* _______ */}; 125 | let b = { 126 | // _______ 127 | }; 128 | 129 | for e in q { 130 | r = *e; // c 131 | } 132 | 133 | while 134 | true 135 | // _______ 136 | {} 137 | 138 | while 139 | true // _______ 140 | {} 141 | 142 | while true {} // _______ 143 | 144 | while true /*_______*/ {} 145 | while true /* _______ */ {} 146 | 147 | while 148 | true && // _______ 149 | true // _______ 150 | {} 151 | 152 | while true {} // _______ 153 | 154 | if cond { 155 | stuff; 156 | } else if /* _______ */ cond { 157 | stuff; 158 | } else { 159 | // _______ 160 | stuff; 161 | } 162 | 163 | if cond { 164 | stuff; 165 | } else { 166 | // _______ 167 | stuff; 168 | } 169 | 170 | ret = if 171 | __DEV__ 172 | // _______ 173 | { 174 | vm.runInContext(source, ctx) 175 | } else { 176 | a 177 | }; 178 | 179 | if a == 0 { 180 | doSomething(); // _______ 181 | } else if a == 1 { 182 | doSomethingElse(); // _______ 183 | } else if a == 2 { 184 | doSomethingElse(); // _______ 185 | } 186 | if a == 0 { 187 | doSomething(); /* _______ */ 188 | } else if a == 1 { 189 | doSomethingElse(); /* _______ */ 190 | } else if a == 2 { 191 | doSomethingElse(); /* _______ */ 192 | } 193 | if a == 0 { 194 | expr; // _______ 195 | } else if a == 1 { 196 | expr; // _______ 197 | } else if a == 2 { 198 | expr; // _______ 199 | } 200 | if a == 0 { 201 | expr; /* _______ */ 202 | } else if a == 1 { 203 | expr; /* _______ */ 204 | } else if a == 2 { 205 | expr; /* _______ */ 206 | } 207 | if a == 0 { 208 | looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong; // _______ 209 | } else if a == 1 { 210 | looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong; // _______ 211 | } else if a == 2 { 212 | looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong; // _______ 213 | } 214 | if code == 92 /* _______ */ { 215 | } 216 | if code == 92 /* _______ */ /* _______ */ { 217 | } 218 | 219 | if code == 92 /* _______ */ { 220 | } 221 | if code == 92 {/* _______ */} 222 | 223 | if 224 | 1 225 | // _______ 226 | { 227 | a; 228 | } 229 | 230 | { 231 | // _______ 232 | 'a: loop { 233 | } 234 | } 235 | { 236 | // _______ 237 | 'a: loop { 238 | } 239 | } 240 | 241 | fn f() { 242 | a 243 | /* _______ */ 244 | } 245 | 246 | fn f() { 247 | a 248 | 249 | /* _______ */ 250 | } 251 | 252 | fn d() {/* _______ */} 253 | 254 | fn f() { 255 | // _______ 256 | f(); 257 | 258 | // _______ 259 | f() 260 | 261 | // _______ 262 | // _______ 263 | } 264 | 265 | fn f() { 266 | // _______ 267 | return 1; 268 | } 269 | 270 | fn f() { 271 | // _______ 272 | return 1; 273 | } 274 | 275 | fn f() { 276 | // _______ 277 | return 1; 278 | } 279 | 280 | fn f() { 281 | // _______ 282 | return 1; 283 | } 284 | 285 | // So this is a very long comment. 286 | // Multi-line, too. 287 | // Will it still format correctly? 288 | unsafe { 289 | a; 290 | } 291 | 292 | {/* a block with a comment */} 293 | { 294 | } 295 | { 296 | // A block with a comment. 297 | } 298 | 299 | fn foo() { 300 | (async { 301 | // Do 302 | // some 303 | // work 304 | }).await; 305 | 306 | (async { 307 | // Do 308 | // some 309 | // work 310 | }).await; 311 | } 312 | 313 | // source: "../../samples/comments/blocks.rs" -------------------------------------------------------------------------------- /tests/output/comments/chain.f.rs: -------------------------------------------------------------------------------- 1 | _ 2 | .a(a) 3 | /* _____________________________________________________________________________ */ 4 | .a(); 5 | 6 | _ 7 | .a( 8 | a 9 | ) /* _____________________________________________________________________________ */ 10 | .a(); 11 | 12 | _ 13 | .a( 14 | a 15 | ) /* _____________________________________________________________________________ */ 16 | .a(); 17 | 18 | Something 19 | // _______ 20 | .getInstance(this.props.dao) 21 | .getters(); 22 | 23 | // _______ 24 | measure().then(|| { 25 | SomethingLong(); 26 | }); 27 | 28 | measure() // _______ 29 | .then(|| { 30 | SomethingLong(); 31 | }); 32 | 33 | const configModel = this.baseConfigurationService 34 | .getCache() 35 | .consolidated // _______ 36 | .merge(this.cachedWorkspaceConfig); 37 | 38 | this 39 | .doWriteConfiguration(target, value, options) // _______ 40 | .then( 41 | || null, 42 | || { 43 | return if options.donotNotifyError { 44 | TPromise.wrapError(error) 45 | } else { 46 | this.onError(error, target, value) 47 | }; 48 | } 49 | ); 50 | 51 | angular 52 | .module("AngularAppModule") 53 | // _______ 54 | .constant("API_URL", "http://localhost:8080/api"); 55 | 56 | // _______ 57 | Observable.of(process) 58 | // _______ 59 | .merge(Observable.never()) 60 | // _______ 61 | .takeUntil( 62 | if throwOnError { 63 | errors.flatMap(Observable.throw) 64 | } else { 65 | errors 66 | } 67 | ) 68 | .takeUntil(exit); 69 | 70 | // source: "../../samples/comments/chain.rs" -------------------------------------------------------------------------------- /tests/output/comments/closure.f.rs: -------------------------------------------------------------------------------- 1 | call(|/*_______*/ row| {}); 2 | KEYPAD_NUMBERS.map( 3 | |num| 4 | // _______ 5 | 1 6 | ); 7 | 8 | const obj = A { 9 | f1: /* _______ */ || {}, 10 | f2: |/* _______ */| {}, 11 | f3: || /* _______ */ {}, 12 | f4: /* _______ */ |/* _______ */| /* _______ */ {}, 13 | }; 14 | 15 | /* _______ */ (|| {})(); 16 | (|/* _______ */| {})(); 17 | (|| /* _______ */ {})(); 18 | /* _______ */ (|/* _______ */| /* _______ */ {})(); 19 | 20 | let commented = | 21 | /* first */ a /*argument*/, 22 | /* second*/ b: WithType /* argument*/, 23 | /* ignored */ _ 24 | | ( 25 | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, 26 | bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, 27 | ); 28 | 29 | const fn1 = |/*_______, _______*/| doSomething(); 30 | const fn2 = |/*_______, _______*/| doSomething(anything); 31 | 32 | foo( 33 | | 34 | // _______ 35 | | {} 36 | ); 37 | 38 | const rootEpic = |actions, store| 39 | combineEpics(epics)(actions, store) 40 | // _______ 41 | .catch(|err, stream| { 42 | getLogger().error(err); 43 | return stream; 44 | }); 45 | 46 | // source: "../../samples/comments/closure.rs" -------------------------------------------------------------------------------- /tests/output/comments/dangling.f.rs: -------------------------------------------------------------------------------- 1 | use std::{/* comment */}; 2 | 3 | macro_rules! m {/* comment */} 4 | macro_rules! m { 5 | /* comment */ /* comment */ (/* comment */) => {/* comment */}; 6 | } 7 | 8 | macro m/* comment */ (/* comment */) {/* comment */} 9 | 10 | {/* comment */} 11 | 12 | f(/* comment */); 13 | 14 | f /* comment */!(/* comment */); 15 | f /* comment */! {/* comment */} 16 | f /* comment */![/* comment */]; 17 | 18 | f!([/* comment */]); 19 | f!({/* comment */}); 20 | f!((/* comment */)); 21 | 22 | f!(~[/* comment */]); 23 | f!(~{/* comment */}); 24 | f!(~(/* comment */)); 25 | 26 | [/* comment */]; 27 | (/* comment */); 28 | A /* comment */ {/* comment */}; 29 | 30 | if let A {/* comment */} | a(/* comment */) | [/* comment */] = (/* comment */) { 31 | } 32 | 33 | if 0 {/* comment */} 34 | if 0 {/* comment */} else { 35 | /* comment */ 36 | /* comment */ 37 | /* comment */ 38 | } 39 | if 0 {/* comment */} else if /* comment */ /* comment */ 0 {/* comment */} 40 | if 0 {/* comment */} else if 41 | /* comment */ /* comment */ /* comment */ let _ = 0 42 | {/* comment */} 43 | 44 | match (/* comment */) {/* comment */} 45 | 46 | fn a(/* comment */) { 47 | /* comment */ 48 | /* comment */ 49 | } 50 | 51 | |/* comment */| 0; 52 | 53 | impl A {/* comment */} 54 | trait A {/* comment */} 55 | enum A {/* comment */} 56 | struct A(/* comment */); 57 | struct A {/* comment */} 58 | mod A {/* comment */} 59 | use A::{/* comment */}; 60 | union A {/* comment */} 61 | 62 | A::; 63 | A::(/* comment */); 64 | 65 | type A 66 | : fn(/* comment */) 67 | where 68 | for A: for Fn(/* comment */) -> (/* comment */); 69 | 70 | #![/* comment */] 71 | #[/* comment */] 72 | struct A; 73 | 74 | #![/* comment */] 75 | #[/* comment */] 76 | struct A; 77 | 78 | #![/* comment */] 79 | #[/* comment */] 80 | #[/* comment */] 81 | struct A; 82 | 83 | #![/* comment */] 84 | #![/* comment */] 85 | #[/* comment */] 86 | struct A; 87 | 88 | #![/* comment */] 89 | #![/* comment */] 90 | #[/* comment */] 91 | #[/* comment */] 92 | struct A; 93 | 94 | #![/* comment */] 95 | #![/* comment */] 96 | #[/* comment */] 97 | #[/* comment */] 98 | struct A; 99 | 100 | // source: "../../samples/comments/dangling.rs" -------------------------------------------------------------------------------- /tests/output/comments/file.f.rs: -------------------------------------------------------------------------------- 1 | // This file only 2 | // has comments. This comment 3 | // should still exist 4 | // 5 | // when printed. 6 | 7 | /** 8 | * @typedef {DataDrivenMapping|ConstantMapping} Mapping 9 | */ 10 | /** 11 | * @typedef {Object.} ConfigurationMapping 12 | */ 13 | 14 | /** 15 | * @typedef {Function} D3Scale - a D3 scale 16 | * @property {Function} ticks 17 | * @property {Function} tickFormat 18 | */ 19 | // comment 20 | 21 | // comment 22 | 23 | // source: "../../samples/comments/file.rs" -------------------------------------------------------------------------------- /tests/output/comments/flow.f.rs: -------------------------------------------------------------------------------- 1 | loop { 2 | break /* _______ */; 3 | continue /* _______ */; 4 | } 5 | 6 | 'loop: loop { 7 | break /* _______ */ 'loop; 8 | break 'loop /* _______ */; 9 | continue /* _______ */ 'loop; 10 | continue 'loop /* _______ */; 11 | } 12 | 13 | return ( 14 | // _______ 15 | !!x 16 | ); 17 | 18 | return 1337; // _______ 19 | 20 | return ( 21 | // _______ 22 | 42 && 84 23 | ); 24 | 25 | return ( 26 | // _______ 27 | 42 * 84 28 | ); 29 | 30 | return if 31 | // _______ 32 | 42 33 | { 34 | 1 35 | } else { 36 | 2 37 | }; 38 | 39 | return if 40 | // _______ 41 | 42 * 3 42 | { 43 | 1 44 | } else { 45 | 2 46 | }; 47 | 48 | return ( 49 | // _______ 50 | a() 51 | ); 52 | 53 | return ( 54 | // _______ 55 | a.b.c 56 | ); 57 | 58 | return ( 59 | // _______ 60 | a.b.c 61 | ); 62 | 63 | return ( 64 | afn 65 | .b() 66 | // _______ 67 | .c.d() 68 | ); 69 | 70 | return ( 71 | // _______ 72 | if a.b() * 3 + 4 + (if ("a`hi`", 1) { 1 } else { 1 }) { 73 | } else { 74 | 1 75 | } 76 | ); 77 | 78 | return ( 79 | // _______ 80 | a, 81 | b, 82 | ); 83 | 84 | return ( 85 | // _______ 86 | a 87 | ); 88 | 89 | return /* _______ */ 42 || 42; 90 | 91 | return ( 92 | observableFromSubscribeFunction() 93 | // _______ 94 | // _______ 95 | .debounceTime(debounceInterval) 96 | ); 97 | 98 | return A { 99 | // _______ 100 | bar: baz() + 1, 101 | }; 102 | 103 | // source: "../../samples/comments/flow.rs" -------------------------------------------------------------------------------- /tests/output/comments/functions.f.rs: -------------------------------------------------------------------------------- 1 | fn a(/* _______ */) {} // _______ 2 | fn b() {} // _______ 3 | fn c(/* _______ */ argA, argB, argC) {} // _______ 4 | fn a(a /*_______*/) {} 5 | fn b(a /*_______*/) {} 6 | fn d(a /*_______*/, b /*_______*/, c /*_______*/, d /*_______*/) {} 7 | fn d(a /*_______*/, b /*_______*/, c /*_______*/, d /*_______*/) {/*_______*/} 8 | // prettier-ignore 9 | fn c(a /*_______*/ 10 | ) {} 11 | // prettier-ignore 12 | fn d( 13 | a /*_______*/, 14 | b /*_______*/, 15 | c /*_______*/, 16 | d /*_______*/ 17 | ) {} 18 | // prettier-ignore 19 | fn e( 20 | a /*_______*/, 21 | b /*_______*/, 22 | c /*_______*/, 23 | d /*_______*/ 24 | ) {} /* _______*/ 25 | 26 | fn f1 /* _______ */() {} 27 | fn f2(/* _______ */) {} 28 | fn f3() {/* _______ */} 29 | fn f4 /* _______ */(/* _______ */) {/* _______ */} 30 | fn f5(/* _______ */ /* _______ */ a) {} 31 | fn f6(/* _______ */ a /* _______ */) {} 32 | fn f7(/* _______ */ /* _______ */ a) {/* _______ */} 33 | 34 | // source: "../../samples/comments/functions.rs" -------------------------------------------------------------------------------- /tests/output/comments/ignore.attr.f.rs: -------------------------------------------------------------------------------- 1 | const baseline = 1 + 1; 2 | 3 | fn no() { 4 | a( a ); #![rustfmt::skip] 5 | // _______ 6 | } 7 | 8 | #[rustfmt::skip] 9 | const a = A { 10 | b: 11 | "_______", 12 | }; 13 | 14 | fn f() { 15 | 1 + 1; 16 | #[no ] 17 | #![rustfmt::skip] 18 | fn f() { 19 | 1 + 1; 20 | } 21 | } 22 | 23 | // source: "../../samples/comments/ignore.attr.rs" -------------------------------------------------------------------------------- /tests/output/comments/ignore.f.rs: -------------------------------------------------------------------------------- 1 | const baseline = 1 + 1; 2 | 3 | // prettier-ignore 4 | let x = 5 | "" + this.USE + " " + this.STRICT + ";\n" + 6 | this.filterPrefix() + 7 | "var fn=" + this.generateFunction("fn", "s,l,a,i") + 8 | extra + 9 | this.watchFns() + 10 | "return fn;"; 11 | 12 | // prettier-ignore 13 | const x = Matrix.create( 14 | 1, 0, 0, 15 | 0, 1, 0, 16 | 0, 0, 0 17 | ); 18 | 19 | // prettier-ignore 20 | const x = A { 21 | b: 22 | "_______", 23 | }; 24 | 25 | fn f() { 26 | a( a ); // prettier-ignore 27 | // _______ 28 | } 29 | 30 | // prettier-ignore 31 | console.error( 32 | "_______" + prompt + "_______" + 33 | "_______ _______" 34 | ); 35 | 36 | const response = A { 37 | // prettier-ignore 38 | a: "Turn on the lights", 39 | intent: "lights", 40 | }; 41 | 42 | verylongidentifierthatwillwrap123123123123123( 43 | a.b 44 | // prettier-ignore 45 | // _______ 46 | .c 47 | ); 48 | 49 | call( 50 | // _______ 51 | a. 52 | // prettier-ignore 53 | b 54 | ); 55 | 56 | call(a( 57 | /* 58 | _______ 59 | */ 60 | 1, 61 | 2.0000, 3 62 | ) 63 | // prettier-ignore 64 | .c); 65 | 66 | #[attr] 67 | // prettier-ignore 68 | const foo = 1 + 1; 69 | 70 | const A { 71 | // prettier-ignore 72 | bar : a, 73 | } = foo; 74 | 75 | const A { 76 | a, 77 | // prettier-ignore 78 | bar2 : a, 79 | } = foo; 80 | 81 | /* _______ */ 82 | const A { 83 | // prettier-ignore 84 | bar3 : a, // _______ 85 | } = foo; 86 | 87 | const A { 88 | // prettier-ignore 89 | bar4 : a /* _______ */, 90 | } = foo; 91 | 92 | const A { 93 | // prettier-ignore 94 | bar5 : /* _______ */ a, 95 | } = foo; 96 | 97 | const A { 98 | // prettier-ignore 99 | .. 100 | } = foo; 101 | 102 | const A { 103 | baz: A { 104 | // prettier-ignore 105 | foo2: [a, b, c], 106 | }, 107 | // prettier-ignore 108 | bar7 : a, 109 | } = foo; 110 | 111 | // source: "../../samples/comments/ignore.rs" -------------------------------------------------------------------------------- /tests/output/comments/ignore.file.f.rs: -------------------------------------------------------------------------------- 1 | const unformatted= 1; 2 | 3 | #![rustfmt::skip] // a 4 | 5 | fn unformatted () { 6 | struct a { 7 | // b 8 | c 9 | } 10 | } 11 | // source: "../../samples/comments/ignore.file.rs" -------------------------------------------------------------------------------- /tests/output/comments/imports.f.rs: -------------------------------------------------------------------------------- 1 | use list::{ 2 | // Some item 3 | SomeItem /* Comment */, 4 | /* Another item */ AnotherItem /* Another Comment */, // Last Item 5 | LastItem, 6 | }; 7 | use test::{ Other /* C */, /* A */ self /* B */ }; 8 | use ::{ /* Pre-comment! */ Foo, Bar /* comment */ }; 9 | 10 | // source: "../../samples/comments/imports.rs" -------------------------------------------------------------------------------- /tests/output/comments/macro.f.rs: -------------------------------------------------------------------------------- 1 | a!(~ " { } "); 2 | a!(~ // 1 3 | ); 4 | a!(~ { // 2 5 | }); 6 | 7 | cfg_if::cfg_if! { 8 | if #[attr] { 9 | if 0 { 10 | } else { 11 | // ERROR! 12 | } 13 | } 14 | } 15 | 16 | a! { 17 | if #[attr] { 18 | // ERROR! 19 | } 20 | } 21 | 22 | x! {~ { 23 | // ERROR! 24 | } 25 | } 26 | 27 | // source: "../../samples/comments/macro.rs" -------------------------------------------------------------------------------- /tests/output/comments/multiple.f.rs: -------------------------------------------------------------------------------- 1 | /* _______ */ /* _______ */ /* _______ */ a; 2 | a; /* _______ */ /* _______ */ /* _______ */ 3 | a; // _______ 4 | a; 5 | /*1*/ /*2*/ /*3*/ 6 | b; 7 | 8 | a; /*1*/ /*2*/ /*3*/ 9 | b; 10 | 11 | a; 12 | /*1*/ /*2*/ /*3*/ b; 13 | 14 | a; 15 | /* 16 | 1*/ /*2*/ /*3 17 | */ 18 | b; 19 | 20 | a; /* 21 | 1*/ /*2*/ 22 | /*3 23 | */ 24 | b; 25 | 26 | a; 27 | /* 28 | 1*/ /*2*/ /*3 29 | */ b; 30 | 31 | a; 32 | /*1*/ /*2*/ 33 | /*3*/ 34 | b; 35 | 36 | a; /*1*/ /*2*/ 37 | /*3*/ 38 | b; 39 | 40 | a; 41 | /*1*/ /*2*/ 42 | /*3*/ b; 43 | 44 | a; 45 | /* 46 | 1*/ /*2*/ 47 | /*3 48 | */ 49 | b; 50 | 51 | a; /* 52 | 1*/ /*2*/ 53 | /*3 54 | */ 55 | b; 56 | 57 | a; /* 58 | 1*/ /*2*/ 59 | /*3 60 | */ b; 61 | 62 | a; 63 | /*1*/ 64 | /*2*/ /*3*/ 65 | b; 66 | 67 | a; /*1*/ 68 | /*2*/ /*3*/ 69 | b; 70 | 71 | a; 72 | /*1*/ 73 | /*2*/ /*3*/ b; 74 | 75 | a; 76 | /* 77 | 1*/ 78 | /*2*/ /*3 79 | */ 80 | b; 81 | 82 | a; /* 83 | 1*/ 84 | /*2*/ /*3 85 | */ 86 | b; 87 | 88 | a; /* 89 | 1*/ 90 | /*2*/ /*3 91 | */ b; 92 | 93 | use foo; /* 94 | 14 95 | */ /* 1 96 | 10 97 | */ /*/ 13 */ 98 | /* 99 | 9 100 | ****/ 101 | use bar; 102 | 103 | x; /* 104 | 1 */ /* 2 */ 105 | 106 | y; 107 | 108 | x; /*1*/ /*2*/ 109 | y; 110 | 111 | /** 1 - OUTER DOC */ 112 | 113 | /* 2 - COMMENT */ 114 | 115 | /*! 3 - INNER DOC */ 116 | 117 | /*! 4 - INNER DOC *//** 118 | 119 | /* 5A - COMMENT */ 120 | * 5B - OUTER DOC 121 | */ 122 | /** 123 | * 5C - OUTER DOC 124 | */ 125 | 126 | // format: lost 1 comments 127 | // source: "../../samples/comments/multiple.rs" -------------------------------------------------------------------------------- /tests/output/comments/parens.f.rs: -------------------------------------------------------------------------------- 1 | !x; 2 | !(x /* 0 */); 3 | !(/* 1 */ x); 4 | !( 5 | /* 2 */ 6 | x 7 | ); 8 | !( 9 | x 10 | /* 3 */ 11 | ); 12 | !( 13 | x // 4 14 | ); 15 | 16 | !(x + y); 17 | !(x + y /* 5 */); 18 | !(/* 6 */ x + y); 19 | a!(!(/* 6 */ x + y)); 20 | !( 21 | /* 7 */ 22 | x + y 23 | ); 24 | !( 25 | x + y 26 | /* 8 */ 27 | ); 28 | !( 29 | x + y // 9 30 | ); 31 | 32 | !(x || y); 33 | !(/* 10 */ x || y); 34 | !(x || y /* 11 */); 35 | !( 36 | /* 12 */ 37 | x || y 38 | ); 39 | !( 40 | x || y 41 | /* 13 */ 42 | ); 43 | !( 44 | x || y // 14 45 | ); 46 | 47 | ![1, 2, 3]; 48 | !([1, 2, 3] /* 15 */); 49 | !(/* 16 */ [1, 2, 3]); 50 | !( 51 | /* 17 */ 52 | [1, 2, 3] 53 | ); 54 | !( 55 | [1, 2, 3] 56 | /* 18 */ 57 | ); 58 | !( 59 | [1, 2, 3] // 19 60 | ); 61 | 62 | !(A { a: 1, b: 2 }); 63 | !(A { a: 1, b: 2 } /* 20 */); 64 | !(/* 21 */ A { a: 1, b: 2 }); 65 | !( 66 | /* 22 */ 67 | A { a: 1, b: 2 } 68 | ); 69 | !( 70 | A { a: 1, b: 2 } 71 | /* 23 */ 72 | ); 73 | !( 74 | A { a: 1, b: 2 } // 24 75 | ); 76 | 77 | !(|| { 78 | return x; 79 | }); 80 | !( 81 | || { 82 | return x; 83 | } /* 25 */ 84 | ); 85 | !( 86 | /* 26 */ || { 87 | return x; 88 | } 89 | ); 90 | !( 91 | /* 27 */ 92 | || { 93 | return x; 94 | } 95 | ); 96 | !( 97 | || { 98 | return x; 99 | } 100 | /* 28 */ 101 | ); 102 | !( 103 | || { 104 | return x; 105 | } // 29 106 | ); 107 | 108 | !({ 109 | x = y; 110 | }); 111 | !( 112 | { 113 | x = y; 114 | } /* 30 */ 115 | ); 116 | !( 117 | /* 31 */ { 118 | x = y; 119 | } 120 | ); 121 | !( 122 | /* 32 */ 123 | { 124 | x = y; 125 | } 126 | ); 127 | !( 128 | { 129 | x = y; 130 | } 131 | /* 33 */ 132 | ); 133 | !( 134 | { 135 | x = y; 136 | } // 34 137 | ); 138 | 139 | !x.y; 140 | !(x.y /* 35 */); 141 | !(/* 36 */ x.y); 142 | !( 143 | /* 37 */ 144 | x.y 145 | ); 146 | !( 147 | x.y 148 | /* 38 */ 149 | ); 150 | !( 151 | x.y // 39 152 | ); 153 | 154 | !x(); 155 | !(x() /* 40 */); 156 | !(/* 41 */ x()); 157 | !( 158 | /* 42 */ 159 | x() 160 | ); 161 | !( 162 | x() 163 | /* 43 */ 164 | ); 165 | !( 166 | x() // 44 167 | ); 168 | 169 | !(x, y); 170 | !(x, y /* 45 */); 171 | !(/* 46 */ x, y); 172 | !( 173 | /* 47 */ 174 | x, 175 | y, 176 | ); 177 | !( 178 | x, 179 | y, 180 | /* 48 */ 181 | ); 182 | !( 183 | x.y // 49 184 | ); 185 | 186 | !(|| 3); 187 | !(|| 3 /* 50 */); 188 | !(/* 51 */ || 3); 189 | !( 190 | /* 52 */ 191 | || 3 192 | ); 193 | !( 194 | || 3 195 | /* 53 */ 196 | ); 197 | !( 198 | || 3 // 54 199 | ); 200 | 201 | loop { 202 | !({ 203 | yield x; 204 | }); 205 | !( 206 | { 207 | yield x; 208 | } /* 55 */ 209 | ); 210 | !( 211 | /* 56 */ { 212 | yield x; 213 | } 214 | ); 215 | !( 216 | /* 57 */ 217 | { 218 | yield x; 219 | } 220 | ); 221 | !( 222 | { 223 | yield x; 224 | } 225 | /* 58 */ 226 | ); 227 | !( 228 | { 229 | yield x; 230 | } // 59 231 | ); 232 | } 233 | 234 | async || { 235 | !x.await; 236 | !(x.await /* 60 */); 237 | !(/* 61 */ x.await); 238 | !( 239 | /* 62 */ 240 | x.await 241 | ); 242 | !( 243 | x.await 244 | /* 63 */ 245 | ); 246 | !( 247 | x.await // 64 248 | ); 249 | }; 250 | 251 | Math.min( 252 | /* ______________________________________________________________ 253 | * _______________________________________________________________ 254 | * _______ */ 255 | document.body.scrollHeight - 256 | (window.scrollY + window.innerHeight) - 257 | devsite_footer_height, 258 | 0 259 | ); 260 | 261 | // source: "../../samples/comments/parens.rs" -------------------------------------------------------------------------------- /tests/output/comments/whitespace.f.rs: -------------------------------------------------------------------------------- 1 | /* 2 | 1 3 | */ 4 | /* 5 | 2 6 | */ 7 | /* 8 | 3 9 | */ 10 | /* 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 4 20 | */ 21 | 22 | /* 23 | 5a 5b 24 | */ 25 | /* 26 | 6 27 | */ 28 | /* 29 | 7a 7b 30 | */ 31 | /* 32 | 8a 8b 33 | */ 34 | 35 | /* 36 | VT4+2: 9 37 | */ 38 | /* 39 | FF4+2: 10 40 | */ 41 | /* 42 | 43 | 44 | 45 | 46 | CR4+2: 11 47 | */ 48 | /* 49 | ………… NEL4+2: 12 50 | */ 51 | /* 52 |      13a 13b 53 | */ 54 | /* 55 |      14 56 | */ 57 | /* 58 |      15a 15b 59 | */ 60 | 61 | /* 62 |   16 63 |   16 64 |    16 65 |   16 66 |     16 67 |    16 68 |     16 69 |   16 70 |     16 71 |     16 72 |      16 73 |    16 74 |      16 75 |     16 76 |      16 77 | */ 78 | 79 | /* */ 80 | /* 81 | 17a 82 | 17b 17c 83 |        17d 84 | */ 85 | /* */ 86 | /* 87 | 18a 88 | 18b 18c 89 |        18d 90 | */ 91 | 92 | // source: "../../samples/comments/whitespace.rs" -------------------------------------------------------------------------------- /tests/output/common/chains.first-argument-expansion.f.rs: -------------------------------------------------------------------------------- 1 | setTimeout(|| { 2 | thing(); 3 | }, 500); 4 | 5 | ["a", "b", "c"].reduce(|item, thing| { 6 | return thing + " " + item; 7 | }, "letters:"); 8 | 9 | func(|| { 10 | thing(); 11 | }, identifier); 12 | 13 | func(|| { 14 | thing(); 15 | }, this.props.timeout * 1000); 16 | 17 | func(|| { 18 | thing(); 19 | }, this.props.getTimeout()); 20 | 21 | func(|| { 22 | thing(); 23 | }, true); 24 | 25 | func(|| { 26 | thing(); 27 | }, null); 28 | 29 | func(|| { 30 | thing(); 31 | }, undefined); 32 | 33 | func(|| { 34 | thing(); 35 | }, piohjougou); 36 | 37 | func(|| { 38 | thing(); 39 | }, 1 || 3); 40 | 41 | func(|| { 42 | return thing(); 43 | }, 1 || 3); 44 | 45 | func( 46 | || { 47 | thing(); 48 | }, 49 | if something() { 50 | someOtherThing() 51 | } else { 52 | somethingElse(true, 0) 53 | } 54 | ); 55 | 56 | func( 57 | || { 58 | thing(); 59 | }, 60 | if something(longArgumentName, anotherLongArgumentName) { 61 | someOtherThing() 62 | } else { 63 | somethingElse(true, 0) 64 | } 65 | ); 66 | 67 | func( 68 | || { 69 | thing(); 70 | }, 71 | if 72 | something( 73 | longArgumentName, 74 | anotherLongArgumentName, 75 | anotherLongArgumentName, 76 | anotherLongArgumentName 77 | ) 78 | { 79 | someOtherThing() 80 | } else { 81 | somethingElse(true, 0) 82 | } 83 | ); 84 | 85 | compose( 86 | |a| { 87 | return a.thing; 88 | }, 89 | |b| b * b 90 | ); 91 | 92 | somthing.reduce( 93 | |item, thing| { 94 | return { 95 | thing.blah = item; 96 | }; 97 | }, 98 | {} 99 | ); 100 | 101 | somthing.reduce(|item, thing| { 102 | return thing.push(item); 103 | }, []); 104 | 105 | reallyLongLongLongLongLongLongLongLongLongLongLongLongLongLongMethod(|f, g, h| { 106 | return f.pop(); 107 | }, true); 108 | 109 | func( 110 | || { 111 | thing(); 112 | }, 113 | true, 114 | false 115 | ); 116 | 117 | func( 118 | || { 119 | thing(); 120 | }, 121 | A { yes: true, cats: 5 } 122 | ); 123 | 124 | compose( 125 | |a| { 126 | return a.thing; 127 | }, 128 | |b| { 129 | return b + ""; 130 | } 131 | ); 132 | 133 | compose( 134 | |a| { 135 | return a.thing; 136 | }, 137 | |b| [1, 2, 3, 4, 5] 138 | ); 139 | 140 | setTimeout( 141 | // _______ 142 | || { 143 | thing(); 144 | }, 145 | 500 146 | ); 147 | 148 | setTimeout( 149 | /* _______ */ || { 150 | thing(); 151 | }, 152 | 500 153 | ); 154 | 155 | func( 156 | |args| { 157 | execute(args); 158 | }, 159 | |result| result && console.log("success") 160 | ); 161 | 162 | beep.boop().baz( 163 | "foo", 164 | A { 165 | some: A { 166 | thing: A { 167 | nested: true, 168 | }, 169 | }, 170 | }, 171 | A { another: A { thing: true } }, 172 | || {} 173 | ); 174 | 175 | db.collection("indexOptionDefault").createIndex( 176 | A { a: 1 }, 177 | A { 178 | indexOptionDefaults: true, 179 | w: 2, 180 | wtimeout: 1000, 181 | }, 182 | |err| { 183 | test.equal(null, err); 184 | test.deepEqual(A { w: 2, wtimeout: 1000 }, commandResult.writeConcern); 185 | 186 | client.close(); 187 | done(); 188 | } 189 | ); 190 | 191 | // source: "../../samples/common/chains.first-argument-expansion.rs" -------------------------------------------------------------------------------- /tests/output/common/destructuring.f.rs: -------------------------------------------------------------------------------- 1 | const [one, two @ null, three @ null] = arr; 2 | a = |[s @ 1]| 1; 3 | const A { children, .. } = this.props; 4 | 5 | const A { user: A { firstName, lastName } } = this.props; 6 | 7 | const A { 8 | name: A { first, last }, 9 | organisation: A { 10 | address: A { street: orgStreetAddress, postcode: orgPostcode }, 11 | }, 12 | } = user; 13 | 14 | fn f(A { data: A { name } }) {} 15 | 16 | const UserComponent = |A { 17 | name: A { first, last }, 18 | organisation: A { 19 | address: A { street: orgStreetAddress, postcode: orgPostcode }, 20 | }, 21 | }| { 22 | return; 23 | }; 24 | 25 | const A { a, b, c, d: A { e } } = someObject; 26 | 27 | for A { data: A { message } } in b { 28 | } 29 | 30 | const obj = A { 31 | func: |id, A { blog: A { title } }| { 32 | return id + title; 33 | }, 34 | }; 35 | 36 | const A { 37 | foo, 38 | bar: bazAndSomething, 39 | quxIsLong, 40 | } = someBigFunctionName("foo")("bar"); 41 | 42 | // source: "../../samples/common/destructuring.rs" -------------------------------------------------------------------------------- /tests/output/common/members.f.rs: -------------------------------------------------------------------------------- 1 | ( 2 | if valid { 3 | helper.responseBody(this.currentUser) 4 | } else { 5 | helper.responseBody(this.defaultUser) 6 | } 7 | ).prop; 8 | 9 | const veryVeryVeryVeryVeryVeryVeryLong = 10 | doc.expandedStates[doc.expandedStates.length - 1]; 11 | const small = doc.expandedStates[doc.expandedStates.length - 1]; 12 | 13 | const promises = [ 14 | promise 15 | .resolve() 16 | .then(console.log) 17 | .catch(|err| { 18 | console.log(err); 19 | return null; 20 | }), 21 | redis.fetch(), 22 | other.fetch(), 23 | ]; 24 | 25 | const promises2 = [ 26 | promise 27 | .resolve() 28 | .veryLongFunctionCall() 29 | .veryLongFunctionCall() 30 | .then(console.log) 31 | .catch(|err| { 32 | console.log(err); 33 | return null; 34 | }), 35 | redis.fetch(), 36 | other.fetch(), 37 | ]; 38 | 39 | window.FooClient 40 | .setVars(A { 41 | locale: getFooLocale(A { page }), 42 | authorizationToken: data.token, 43 | }) 44 | .initVerify("foo_container"); 45 | 46 | window.something.FooClient 47 | .setVars(A { 48 | locale: getFooLocale(A { page }), 49 | authorizationToken: data.token, 50 | }) 51 | .initVerify("foo_container"); 52 | 53 | window.FooClient.something 54 | .setVars(A { 55 | locale: getFooLocale(A { page }), 56 | authorizationToken: data.token, 57 | }) 58 | .initVerify("foo_container"); 59 | 60 | (veryLongVeryLongVeryLong || e).prop; 61 | 62 | ( 63 | veryLongVeryLongVeryLong || 64 | anotherVeryLongVeryLongVeryLong || 65 | veryVeryVeryLongError 66 | ).prop; 67 | 68 | const x = A { 69 | ABC: "12345678901234567890123456789012345678901234567890123456789012345678901234567890", 70 | }; 71 | const a = classnames(A { 72 | aaaaaaaaaaaa: this.state.longLongLongLongLongLongLongLongLongTooLongProp, 73 | }); 74 | 75 | const b = classnames(A { 76 | aaaaaaaaaaaa: this.state.longLongLongLongLongLongLongLongLongTooLongProp == 77 | true, 78 | }); 79 | 80 | const c = classnames(A { 81 | aaaaaaaaaaaa: ["foo", "bar", "foo", "bar", "foo", "bar", "foo", "bar", "foo"], 82 | }); 83 | 84 | const d = classnames(A { 85 | aaaaaaaaaaaa: || {}, 86 | }); 87 | 88 | const e = classnames(A { 89 | aaaaaaaaaaaa: || {}, 90 | }); 91 | 92 | const f = classnames(A { 93 | aaaaaaaaaaaa: A { 94 | foo: "bar", 95 | bar: "foo", 96 | foo: "bar", 97 | bar: "foo", 98 | foo: "bar", 99 | }, 100 | }); 101 | 102 | const g = classnames(A { 103 | aaaaaaaaaaaa: longLongLongLongLongLongLongLongLongLongLongLongLongTooLongVar || 104 | 1337, 105 | }); 106 | 107 | const h = A { foo: "bar", baz: r"Lorem 108 | ipsum" }; 109 | 110 | // source: "../../samples/common/members.rs" -------------------------------------------------------------------------------- /tests/output/issues/14.f.rs: -------------------------------------------------------------------------------- 1 | [10.0, 10.0, 10.0, 10]; 2 | 3 | // source: "../../samples/issues/14.rs" -------------------------------------------------------------------------------- /tests/output/issues/21/fn_comment.f.rs: -------------------------------------------------------------------------------- 1 | fn eof() {} 2 | // comment 3 | 4 | // source: "../../../samples/issues/21/fn_comment.rs" -------------------------------------------------------------------------------- /tests/output/issues/21/fn_fn.f.rs: -------------------------------------------------------------------------------- 1 | fn eof1() {} 2 | fn eof2() {} 3 | 4 | // source: "../../../samples/issues/21/fn_fn.rs" -------------------------------------------------------------------------------- /tests/output/issues/21/fn_ln.f.rs: -------------------------------------------------------------------------------- 1 | fn eof() {} 2 | 3 | // source: "../../../samples/issues/21/fn_ln.rs" -------------------------------------------------------------------------------- /tests/output/issues/21/ln_fn_ln.f.rs: -------------------------------------------------------------------------------- 1 | fn eof() {} 2 | 3 | // source: "../../../samples/issues/21/ln_fn_ln.rs" -------------------------------------------------------------------------------- /tests/output/issues/21/mod.f.rs: -------------------------------------------------------------------------------- 1 | mod eof {} 2 | 3 | // source: "../../../samples/issues/21/mod.rs" -------------------------------------------------------------------------------- /tests/output/issues/22.f.rs: -------------------------------------------------------------------------------- 1 | fn preserve_last_semicolon() { 2 | if let Some(left) = node.borrow().left.as_ref() { 3 | deque.push_back(left.clone()); 4 | } 5 | if let Some(right) = node.borrow().right.as_ref() { 6 | deque.push_back(right.clone()); 7 | }; 8 | } 9 | 10 | fn a() { 11 | if let Ok(_) = lock.try_lock() { 12 | }; 13 | } 14 | 15 | fn b() { 16 | let lock = std::sync::Mutex::new(10); 17 | match lock.try_lock() { 18 | Ok(_) => {} 19 | Err(_) => {} 20 | } 21 | match lock.try_lock() { 22 | Ok(_) => {} 23 | Err(_) => {} 24 | }; 25 | } 26 | 27 | fn c() { 28 | if let Ok(_) = lock.try_lock() { 29 | }; 30 | // comment 31 | } 32 | 33 | fn d() { 34 | if let Ok(_) = lock.try_lock() { 35 | }; // comment 36 | } 37 | 38 | fn e() { 39 | if let Ok(_) = lock.try_lock() { 40 | } /** comment */; 41 | } 42 | 43 | fn f() { 44 | if let Ok(_) = lock.try_lock() { 45 | }; 46 | } 47 | 48 | fn g() { 49 | if let Ok(_) = lock.try_lock() { 50 | }; 51 | // comment 52 | } 53 | 54 | fn h() { 55 | if let Ok(_) = lock { 56 | } 57 | if let Ok(_) = lock { 58 | } 59 | } 60 | 61 | fn i() { 62 | match lock { 63 | } 64 | match lock { 65 | } 66 | } 67 | 68 | fn inner_attr() { 69 | if let Ok(_) = lock.try_lock() { 70 | } 71 | #![attr] 72 | } 73 | 74 | // source: "../../samples/issues/22.rs" -------------------------------------------------------------------------------- /tests/output/issues/25.f.rs: -------------------------------------------------------------------------------- 1 | #[generator(yield(i32))] 2 | fn nums() { 3 | yield_!(3); 4 | } 5 | 6 | // some extra samples to track changes 7 | #[// 0 8 | generator( 9 | // 1 10 | // 2 11 | yield( 12 | // 3 13 | // 4 14 | i32 15 | // 5 16 | ) 17 | // 6 18 | )] 19 | // 7 20 | 21 | // non-conventional syntax (does not format) 22 | #[#[a] generator( #[b] yield( #[c] i32 ))] 23 | #[generator (a( #[generator(b(i32))] i32 ) )] 24 | #[generator (a( #[generator(yield(i32))] i32 ) )] 25 | #[generator (yield( #[generator(b(i32))] i32 ) )] 26 | #[generator (yield( #[generator(yield(i32))] i32 ) )] 27 | fn f() { 28 | yield_!(3); 29 | } 30 | 31 | // macros in attr (does not format) 32 | #[attr(foo!( ))] 33 | fn f() {} 34 | 35 | // source: "../../samples/issues/25.rs" -------------------------------------------------------------------------------- /tests/output/issues/nth-pass.f.1.rs: -------------------------------------------------------------------------------- 1 | // prettier for javascript cannot format those in one pass 2 | 3 | return ( 4 | // _______ 5 | 42 * 84 + 2 6 | ); 7 | return ( 8 | // _______ 9 | 42 + 84 * 2 10 | ); 11 | 12 | foo.x.y // comment after parent // foo 13 | // comment 1 14 | .bar() // comment after bar() 15 | // comment 2 16 | .foobar // comment after 17 | // comment 3 18 | .baz(x, y, z); 19 | 20 | let zzzz = 21 | // comment 0 22 | expr?.another???.another????.another?.another?; // comment after parent // comment 1 // comment 2 // comment 3 23 | 24 | [ 25 | { 26 | a = b; 27 | }, 28 | 29 | c, // 30 | ]; 31 | 32 | // format: lost 4 comments 33 | // source: "../../samples/issues/nth-pass.rs" -------------------------------------------------------------------------------- /tests/output/issues/nth-pass.f.rs: -------------------------------------------------------------------------------- 1 | // prettier for javascript cannot format those in one pass 2 | 3 | return ( 4 | // _______ 5 | 42 * 6 | 84 + 7 | 2 8 | ); 9 | return ( 10 | // _______ 11 | 42 + 12 | 84 * 2 13 | ); 14 | 15 | foo// comment after parent // foo 16 | .x.y 17 | // comment 1 18 | .bar() // comment after bar() 19 | // comment 2 20 | .foobar// comment after 21 | // comment 3 22 | .baz(x, y, z); 23 | 24 | let zzzz = 25 | // comment 0 26 | expr?.another???.another????.another?.another?; // comment after parent // comment 1 // comment 2 // comment 3 27 | 28 | [ 29 | { 30 | a = b; 31 | }, 32 | 33 | c, // 34 | ]; 35 | 36 | // format: lost 4 comments 37 | // source: "../../samples/issues/nth-pass.rs" -------------------------------------------------------------------------------- /tests/output/macros/cfg_if.f.rs: -------------------------------------------------------------------------------- 1 | [ 2 | cfg_if! { 3 | if #[cfg(def)] { 4 | use std; 5 | 0 6 | } 7 | }, 8 | cfg_if! { 9 | if #[cfg(def)] { 10 | use std; 11 | 0 12 | } else { 13 | 1 14 | } 15 | }, 16 | cfg_if! { 17 | if #[cfg(abc)] { 0 } else { 1 } 18 | }, 19 | cfg_if! { 20 | if #[cfg(abc)] { 0 } else if #[cfg(def)] { 1 } 21 | }, 22 | cfg_if! { 23 | if #[cfg(abc)] { 0 } else if #[cfg(def)] { 1 } else { 0 } 24 | }, 25 | 26 | cfg_if! {}, 27 | cfg_if! { // comment 28 | if #[cfg(abc)] { 29 | 0 30 | } 31 | }, 32 | cfg_if! { 33 | if #[cfg(abc)] { 34 | /// comment 35 | /// comment 36 | /// comment 37 | struct A { 38 | //! comment 39 | a: u8, 40 | } 41 | } 42 | }, 43 | cfg_if! { 44 | if #[cfg(abc)] { 45 | struct A { 46 | //! comment 47 | // comment 48 | /// comment 49 | a: u8, 50 | } 51 | } 52 | }, 53 | cfg_if! { 54 | if #[cfg(abc)] { 55 | struct A { 56 | /// comment 57 | a: u8, 58 | } 59 | } 60 | }, 61 | cfg_if! { 62 | if #[cfg(abc)] { 63 | struct A { 64 | //! comment 65 | } 66 | } 67 | }, 68 | cfg_if! { 69 | if #[cfg(abc)] { 70 | struct A { 71 | /// comment 72 | } 73 | } 74 | }, 75 | cfg_if! { if true{} }, 76 | ]; 77 | 78 | // source: "../../samples/macros/cfg_if.rs" -------------------------------------------------------------------------------- /tests/output/macros/if_chain.f.rs: -------------------------------------------------------------------------------- 1 | [ 2 | if_chain! { 3 | if let Some(a) = b; 4 | if let Err(a) = b; 5 | let (a, b) = c; 6 | if 1 + 2; 7 | then { d=0; } 8 | }, 9 | if_chain! { 10 | then { d=0; } 11 | }, 12 | if_chain! { 13 | then { d=0; } 14 | else { d!(); } 15 | }, 16 | if_chain! { 17 | if let A::B | A::C = D; 18 | then { 0 } else { 1 } 19 | }, 20 | if_chain! { 21 | let Ok(a) | Err(b) = c; 22 | then { d!(); } 23 | else { d!(); } 24 | }, 25 | if_chain! { 26 | if 1 + 1; 27 | let a: u32 = 3; 28 | 29 | then { d!(); } 30 | else { d!(); } 31 | }, 32 | ]; 33 | 34 | // source: "../../samples/macros/if_chain.rs" -------------------------------------------------------------------------------- /tests/output/macros/matches.f.rs: -------------------------------------------------------------------------------- 1 | [ 2 | matches!(1 + 1, Some(_)), 3 | matches!(1 + 1, Some(_) | None if 1 + 1 == 2), 4 | matches!(1 + 1, | Some(_) | None if 1 + 1 == 2), 5 | ]; 6 | 7 | // source: "../../samples/macros/matches.rs" -------------------------------------------------------------------------------- /tests/output/styling/blockify.f.rs: -------------------------------------------------------------------------------- 1 | [ 2 | || 0, 3 | || { 4 | match 0 { 5 | } 6 | }, 7 | || ( 8 | if 0 { 9 | } 10 | ), 11 | || { 12 | loop { 13 | } 14 | }, 15 | || const {}, 16 | || async {}, 17 | 18 | || -> T { 0 }, 19 | || -> T { 20 | match 0 { 21 | } 22 | }, 23 | || -> T { 24 | if 0 { 25 | } 26 | }, 27 | || -> T { 28 | loop { 29 | } 30 | }, 31 | || -> T const {}, 32 | || -> T async {}, 33 | ]; 34 | 35 | // source: "../../samples/styling/blockify.rs" -------------------------------------------------------------------------------- /tests/output/styling/canInlineBlockBody.f.rs: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | if 0 { 4 | 0 5 | } 6 | }, 7 | { 8 | if 0 { 0 } else { 0 } 9 | }, 10 | { 11 | while 0 { 12 | 0; 13 | } 14 | }, 15 | { 16 | unsafe { 0 } 17 | }, 18 | 19 | { 20 | 0; 21 | if 0 { 22 | 0 23 | } 24 | }, 25 | { 26 | 0; 27 | if 0 { 28 | 0 29 | } else { 30 | 0 31 | } 32 | }, 33 | { 34 | 0; 35 | while 0 { 36 | 0; 37 | } 38 | }, 39 | { 40 | 0; 41 | unsafe { 0 } 42 | }, 43 | 44 | f(async {}), 45 | f(async { 1 }), 46 | f(async { 47 | 1; 48 | }), 49 | 50 | { 51 | async {} 52 | }, 53 | { 54 | async { 1 } 55 | }, 56 | { 57 | async { 58 | 1; 59 | } 60 | }, 61 | 62 | { 63 | 0; 64 | async {} 65 | }, 66 | { 67 | 0; 68 | async { 1 } 69 | }, 70 | { 71 | 0; 72 | async { 73 | 1; 74 | } 75 | }, 76 | 77 | if (0 as u8) < 1 {} else {}, 78 | { 79 | 0; 80 | if (0 as u8) < 1 { 81 | } else { 82 | } 83 | }, 84 | if (0 as u8) < 1 {} else if (0 as u8) < 1 {}, 85 | 86 | if 0 { 87 | } else { 88 | 0; 89 | }, 90 | if 0 { 91 | } else if 1 { 92 | 0; 93 | } else { 94 | }, 95 | if 0 { 96 | } else if 1 { 97 | } else { 98 | 0; 99 | }, 100 | 101 | if 0 { 102 | 0; 103 | } else { 104 | }, 105 | 106 | if 0 { 107 | 0; 108 | } else { 109 | 2 110 | }, 111 | if 0 { 112 | 2 113 | } else { 114 | 0; 115 | }, 116 | 117 | match 0 { 118 | 0 => 0, 119 | 0 => { 0 } 120 | }, 121 | 122 | f(if 0 { 1 } else { 2 }), 123 | f( 124 | { 125 | 0; 126 | }, 127 | if 0 { 128 | 1 129 | } else { 130 | 2 131 | } 132 | ), 133 | 0 + (if 0 { 1 } else { 2 }), 134 | { 0 + (if 0 { 1 } else { 2 }) }, 135 | ({ 136 | 0; 137 | }) + (if 0 { 1 } else { 2 }), 138 | 139 | match 0 { 140 | 0 => { 141 | break 0; 142 | } 143 | 0 => { 144 | o = 0; 145 | } 146 | 0 => 147 | match 0 { 148 | } 149 | 0 => if 0 {} else {} 150 | 0 => if 0 { 151 | } 152 | }, 153 | 154 | || { 155 | loop { 156 | match 0 { 157 | 0 => { 158 | break 0; 159 | } 160 | 0 => { 161 | o = 0; 162 | } 163 | 0 => 164 | match 0 { 165 | } 166 | 0 => if 0 {} else {} 167 | 0 => if 0 { 168 | } 169 | } 170 | } 171 | }, 172 | ]; 173 | 174 | // source: "../../samples/styling/canInlineBlockBody.rs" -------------------------------------------------------------------------------- /tests/output/styling/needsParens.f.rs: -------------------------------------------------------------------------------- 1 | let (A {} | a() | []) = (); 2 | if let A {} | a() | [] = () { 3 | } 4 | 5 | type A: B + C; 6 | type A: (impl B + C); 7 | 8 | trait A = B + C; 9 | trait A = (impl B + C); 10 | 11 | // source: "../../samples/styling/needsParens.rs" -------------------------------------------------------------------------------- /tests/output/styling/needsSemi.f.rs: -------------------------------------------------------------------------------- 1 | fn f() { 2 | #[cfg(unix)] 3 | { 4 | 0 5 | } 6 | #[cfg(windows)] 7 | { 8 | 1 9 | } 10 | } 11 | 12 | // source: "../../samples/styling/needsSemi.rs" -------------------------------------------------------------------------------- /tests/print.ts: -------------------------------------------------------------------------------- 1 | import { createPrettierPrinter, rs_print_samples } from "../ext/jinx-rust/scripts/utils"; 2 | import plugin from "../src/index"; 3 | 4 | // for_each_ts_file(path.resolve("src"), (file) => { 5 | // console.log(cmd(file.path), file.content.includes("\r")); 6 | // update_file(file.path, file.content.replace(/\r/g, ""), { force: true, sync: true, prettier: false }); 7 | // }); 8 | const printer = createPrettierPrinter( 9 | { 10 | parser: "jinx-rust", 11 | plugins: [plugin], 12 | printWidth: 80, 13 | tabWidth: 2, 14 | }, 15 | false 16 | ); 17 | rs_print_samples(["tests/samples/"], "tests/output/", [printer]); 18 | rs_print_samples(["ext/jinx-rust/tests/samples"], "tests/output-ext/", [printer]); 19 | -------------------------------------------------------------------------------- /tests/samples/comments/assignment.rs: -------------------------------------------------------------------------------- 1 | f1 = | 2 | //comment 3 | a 4 | | {}; 5 | 6 | f2 = | 7 | a //comment 8 | | {}; 9 | 10 | f3 = | 11 | a 12 | //comment 13 | | {}; 14 | 15 | f4 = // Comment 16 | || {}; 17 | 18 | f5 = 19 | 20 | // Comment 21 | 22 | || {} 23 | 24 | f6 = /* comment */ 25 | 26 | // Comment 27 | 28 | || {} 29 | 30 | let f4 = // Comment 31 | || {}; 32 | 33 | let f5 = 34 | 35 | // Comment 36 | 37 | || {} 38 | 39 | let f6 = /* comment */ 40 | 41 | // Comment 42 | 43 | || {} 44 | 45 | const kochabCooieGameOnOboleUnweave = // ??? 46 | annularCooeedSplicesWalksWayWay; 47 | 48 | const bifornCringerMoshedPerplexSawder = // !!! 49 | glimseGlyphsHazardNoopsTieTie + 50 | averredBathersBoxroomBuggyNurl - 51 | anodyneCondosMalateOverateRetinol; 52 | 53 | fnNumber = 54 | // Comment 55 | 3; 56 | 57 | fnNumber = 58 | 59 | // Comment 60 | 61 | 3; 62 | 63 | fnNumber = 64 | // Comment0 65 | // Comment1 66 | 3; 67 | 68 | fnNumber = /* comment */ 69 | 3; 70 | 71 | fnNumber = /* comments0 */ 72 | /* comments1 */ 73 | 3; 74 | 75 | fnNumber = 76 | // Comment 77 | 3; 78 | 79 | let fnNumber = 80 | 81 | // Comment 82 | 83 | 3; 84 | 85 | let fnNumber = 86 | // Comment0 87 | // Comment1 88 | 3; 89 | 90 | let fnNumber = /* comment */ 91 | 3; 92 | 93 | let fnNumber = /* comments0 */ 94 | /* comments1 */ 95 | 3; 96 | 97 | fnString = 98 | // Comment 99 | "some" + "long" + "string"; 100 | 101 | fnString = 102 | // Comment 103 | 104 | "some" + "long" + "string"; 105 | 106 | fnString = 107 | 108 | // Comment 109 | 110 | "some" + "long" + "string"; 111 | 112 | fnString = 113 | /* comment */ 114 | "some" + "long" + "string"; 115 | 116 | fnString = 117 | /** 118 | * multi-line 119 | */ 120 | "some" + "long" + "string"; 121 | 122 | fnString = 123 | /* inline */ "some" + "long" + "string" + "some" + "long" + "string" + "some" + "long" + "string" + "some" + "long" + "string"; 124 | 125 | fnString = // Comment0 126 | // Comment1 127 | "some" + "long" + "string"; 128 | 129 | fnString = // Comment 130 | "some" + "long" + "string"; 131 | 132 | fnString = 133 | // Comment 134 | "some" + "long" + "string"; 135 | 136 | let fnString = 137 | // Comment 138 | 139 | "some" + "long" + "string"; 140 | 141 | let fnString = 142 | 143 | // Comment 144 | 145 | "some" + "long" + "string"; 146 | 147 | let fnString = 148 | /* comment */ 149 | "some" + "long" + "string"; 150 | 151 | let fnString = 152 | /** 153 | * multi-line 154 | */ 155 | "some" + "long" + "string"; 156 | 157 | let fnString = 158 | /* inline */ "some" + "long" + "string" + "some" + "long" + "string" + "some" + "long" + "string" + "some" + "long" + "string"; 159 | 160 | let fnString = // Comment0 161 | // Comment1 162 | "some" + "long" + "string"; 163 | 164 | let fnString = // Comment 165 | "some" + "long" + "string"; 166 | 167 | 168 | let obj1 = // 36_______ 169 | A { 170 | key: "val" 171 | } 172 | 173 | let obj2 // 37_______ 174 | = A { 175 | key: "val" 176 | } 177 | 178 | let obj3 = A { // 38_______ 179 | key: "val" 180 | } 181 | 182 | let obj4 = A { 183 | // 39_______ 184 | key: "val" 185 | } 186 | 187 | let obj5 = // 40_______ 188 | [ 189 | "val" 190 | ] 191 | 192 | let obj6 // 41_______ 193 | = [ 194 | "val" 195 | ] 196 | 197 | let obj7 = [ // 42_______ 198 | "val" 199 | ] 200 | 201 | let obj8 = [ 202 | // 43_______ 203 | "val" 204 | ] 205 | 206 | 207 | const A{ a /* 0_______ */ : 1 } = b; 208 | 209 | const A{ c : 1 /* 1_______ */ } = d; 210 | 211 | let A{d //2_______ 212 | : b} = c 213 | 214 | const foo = A { 215 | a: "a" /* 3_______________ */, 216 | 217 | /* 4_________ */ 218 | b: "b", 219 | }; 220 | 221 | let // 44_______ 222 | foo1 = "val"; 223 | 224 | const foo3 = 123 225 | // 45_______ 226 | ;["2", "3"].forEach(|x| console.log(x)) 227 | 228 | let a = b || /** 46_______ */ 229 | (c); 230 | 231 | let a = A { 232 | a /* 47_______ */: || 1 233 | }; 234 | 235 | let a /* 48 */ = 0; 236 | 237 | let b /* 238 | * 4 239 | * 9 240 | */ = 0; 241 | 242 | let c = /* 243 | * 5 244 | * 0 245 | */ 0; 246 | 247 | let d /* 248 | * 5 249 | 250 | * 1 251 | */ = 0; 252 | 253 | fn foo() { 254 | let x = foo 255 | .bar?? ? // comment 256 | .baz; 257 | let x = foo 258 | .bar? ?? 259 | // comment 260 | .baz; 261 | let x = foo 262 | .bar? ? ? // comment 263 | // comment 264 | .baz; 265 | let x = foo 266 | .bar? ?? // comment 267 | // comment 268 | ? ?? 269 | // comment 270 | ? ?? 271 | // comment 272 | ??? 273 | // comment 274 | ? ? ? 275 | .baz; 276 | let x = try /* Invisible comment */ { foo()? }; 277 | let loooooooooooooooooooooooooooooooooooooooooong = does_this?.look?.good?.should_we_break?.after_the_first_question_mark?; 278 | 279 | let x = y // comment 280 | .z; 281 | 282 | self.rev_dep_graph 283 | .iter() 284 | // Remove nodes that are not dirty 285 | .filter(|&(unit, _)| dirties.contains(&unit)) 286 | // Retain only dirty dependencies of the ones that are dirty 287 | .map(|(k, deps)| { 288 | ( 289 | k.clone(), 290 | deps.iter() 291 | .cloned() 292 | .filter(|d| dirties.contains(&d)) 293 | .collect(), 294 | ) 295 | }); 296 | 297 | let y = expr /* comment */.kaas()?; 298 | 299 | (Foo { 300 | ..// comment 301 | a 302 | } = a); 303 | } 304 | -------------------------------------------------------------------------------- /tests/samples/comments/binaryish.rs: -------------------------------------------------------------------------------- 1 | a = b || /** 5_______ */ 2 | c; 3 | 4 | a = b /** 6_______ */ || 5 | c; 6 | 7 | a = b || /** 7_____________________________________________________________________________ */ 8 | c; 9 | 10 | a = b /** 8_____________________________________________________________________________ */ || 11 | c; 12 | 13 | a = b || /** 9_____________________________________________________________________________ */ c; 14 | 15 | a = b && /** 10_______ */ 16 | c; 17 | 18 | a = b /** 11_______ */ && 19 | c; 20 | 21 | a = b && /** 12_____________________________________________________________________________ */ 22 | c; 23 | 24 | a = b /** 13_____________________________________________________________________________ */ && 25 | c; 26 | 27 | a = b && /** 14_____________________________________________________________________________ */ c; 28 | 29 | a = b + /** 15_______ */ 30 | c; 31 | 32 | a = b /** 16_______ */ + 33 | c; 34 | 35 | a = b + /** 17_____________________________________________________________________________ */ 36 | c; 37 | 38 | a = b /** 18_____________________________________________________________________________ */ + 39 | c; 40 | 41 | a = b + /** 19_____________________________________________________________________________ */ c; 42 | 43 | 44 | a = b || // 20_______ 45 | c; 46 | 47 | a = b || // 21_____________________________________________________________________________ 48 | c; 49 | 50 | a = b && // 22_______ 51 | c; 52 | 53 | a = b && // 23_____________________________________________________________________________ 54 | c; 55 | 56 | a = b + // 24_______ 57 | c; 58 | 59 | a = b + // 25_____________________________________________________________________________ 60 | c; 61 | 62 | 0 63 | // 26_______ 64 | + x; 65 | 66 | 0 67 | // 27_______ 68 | * x; 69 | 0 70 | // 28_______ 71 | / x; 72 | 0 73 | // 29_______ 74 | - x; 75 | 0 76 | // 30_______ 77 | % x; 78 | 0 79 | // 31_______ 80 | << x; 81 | 0 82 | // 32_______ 83 | >> x; 84 | 0 85 | // 33_______ 86 | & x; 87 | 0 88 | // 34_______ 89 | | x; 90 | 0 91 | // 35_______ 92 | ^ x; 93 | -------------------------------------------------------------------------------- /tests/samples/comments/blocks.rs: -------------------------------------------------------------------------------- 1 | if 0 { 2 | 0; 3 | // 4 | } else if 0 { 5 | } 6 | 7 | if 1 { 8 | /* 9 | * _______ 10 | */ 11 | } 12 | 13 | if 1 { 14 | // _______ 15 | } 16 | 17 | if 1 { 18 | } 19 | // _______ 20 | else { 21 | 22 | } 23 | 24 | if 1 25 | // if 1 (ln trailing) 26 | { 27 | 1 28 | } 29 | // else if 2 (leading) 30 | else if 2 31 | { 2 } 32 | // else if 3 (leading) 33 | // else if 3 (leading) 34 | // else if 3 (leading) 35 | else if 3 36 | // if 3 (ln trailing) 37 | { 3 } 38 | // else if 4 (leading) 39 | else if 4 { 40 | // 4 body 41 | } 42 | // else (leading) 43 | else { 44 | } 45 | 46 | if 5 // if 5 (trailing) 47 | { 1 } 48 | 49 | if 6 // if 6 (trailing) 50 | { 6 } 51 | else if 7 // else if 7 (trailing) 52 | { 7 } 53 | else // else (trailing) 54 | { 0 } 55 | 56 | if 8 // if 8 (trailing) 57 | // ^ if 8 (ln trailing) 58 | { 1 } 59 | else if 9 // else if 9 60 | // else if 9 (ln trailing) 61 | { 1 } 62 | else // else (trailing) 63 | // else (ln trailing) 64 | { 1 } 65 | 66 | if 10 /* _______ */ // _______ 67 | { 10 } 68 | else if 11 /* _______ */ 69 | { 11 } 70 | else if 12 // _______ /* _______ */ // _______ 71 | { 12 } 72 | else if 13 /* _______ */ /* _______ */ // _______ 73 | { 13 } 74 | else /* _______ */ 75 | { 0 } 76 | 77 | if 14 // _______ 78 | /* _______ */ 79 | // _______ 80 | { 14 } 81 | else if 15 // _______ 82 | /* _______ */ 83 | /* _______ */ // _______ 84 | { 15 } 85 | 86 | 87 | for // _______ 88 | a in b {} 89 | 90 | for /* _______ */ a in b {} 91 | 92 | let a = {/* _______ */}; 93 | let b = { 94 | // _______ 95 | }; 96 | 97 | for e in q { 98 | r = *e; // c 99 | } 100 | 101 | while 102 | true 103 | // _______ 104 | {} 105 | 106 | while true // _______ 107 | {} 108 | 109 | while true {}// _______ 110 | 111 | while true /*_______*/{} 112 | while true /* _______ */ {} 113 | 114 | while 115 | true // _______ 116 | && true // _______ 117 | {} 118 | 119 | while true {} // _______ 120 | 121 | 122 | if (cond) { 123 | stuff; 124 | } /* _______ */ else if (cond) { 125 | stuff; 126 | } 127 | // _______ 128 | else { 129 | stuff; 130 | } 131 | 132 | if (cond){ stuff;} 133 | // _______ 134 | else {stuff;} 135 | 136 | ret = if __DEV__ 137 | // _______ 138 | {vm.runInContext(source, ctx)} 139 | else {a} 140 | 141 | if (a == 0) {doSomething(); // _______ 142 | }else if (a == 1){ doSomethingElse(); // _______ 143 | }else if (a == 2) {doSomethingElse(); // _______ 144 | } 145 | if (a == 0) {doSomething(); /* _______ */ 146 | }else if (a == 1){ doSomethingElse(); /* _______ */ 147 | }else if (a == 2){ doSomethingElse(); /* _______ */ 148 | } 149 | if (a == 0){ expr; // _______ 150 | }else if (a == 1){ expr; // _______ 151 | }else if (a == 2){ expr; // _______ 152 | } 153 | if (a == 0){ expr; /* _______ */ 154 | }else if (a == 1){ expr; /* _______ */ 155 | }else if (a == 2){ expr; /* _______ */ 156 | } 157 | if (a == 0) {looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong; // _______ 158 | }else if (a == 1){ looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong; // _______ 159 | }else if (a == 2){ looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong; // _______ 160 | } 161 | if (code == 92 /* _______ */) {} 162 | if (code == 92 /* _______ */ /* _______ */) {} 163 | 164 | if (code == 92) /* _______ */ {} 165 | if (code == 92) { /* _______ */ } 166 | 167 | if ( 168 | 1 169 | // _______ 170 | ) { 171 | a; 172 | } 173 | 174 | { 175 | 'a: // _______ 176 | loop {} 177 | } 178 | { 179 | 'a: 180 | // _______ 181 | loop { } 182 | } 183 | 184 | 185 | fn f() { 186 | a 187 | /* _______ */ 188 | } 189 | 190 | fn f() { 191 | a 192 | 193 | /* _______ */ 194 | } 195 | 196 | fn d() { 197 | /* _______ */ 198 | } 199 | 200 | fn f() { 201 | // _______ 202 | f() 203 | 204 | // _______ 205 | f() 206 | 207 | // _______ 208 | // _______ 209 | } 210 | 211 | 212 | fn f() 213 | // _______ 214 | { 215 | return 1 216 | } 217 | 218 | fn f() // _______ 219 | { 220 | return 1 221 | } 222 | 223 | fn f() { // _______ 224 | return 1 225 | } 226 | 227 | fn f() { 228 | // _______ 229 | return 1; 230 | } 231 | 232 | unsafe // So this is a very long comment. 233 | // Multi-line, too. 234 | // Will it still format correctly? 235 | { 236 | a 237 | } 238 | 239 | { /* a block with a comment */ } 240 | { 241 | 242 | } 243 | { 244 | // A block with a comment. 245 | } 246 | 247 | fn foo() { 248 | async { 249 | // Do 250 | // some 251 | // work 252 | } 253 | .await; 254 | 255 | async { 256 | // Do 257 | // some 258 | // work 259 | } 260 | .await; 261 | } 262 | -------------------------------------------------------------------------------- /tests/samples/comments/chain.rs: -------------------------------------------------------------------------------- 1 | _.a(a) 2 | /* _____________________________________________________________________________ */ 3 | .a() 4 | 5 | _.a( 6 | a 7 | )/* _____________________________________________________________________________ */ 8 | .a(); 9 | 10 | _.a( 11 | a 12 | ) /* _____________________________________________________________________________ */.a(); 13 | 14 | Something 15 | // _______ 16 | .getInstance(this.props.dao) 17 | .getters() 18 | 19 | // _______ 20 | measure() 21 | .then(|| { 22 | SomethingLong(); 23 | }); 24 | 25 | measure() // _______ 26 | .then(|| { 27 | SomethingLong(); 28 | }); 29 | 30 | const configModel = this.baseConfigurationService.getCache().consolidated // _______ 31 | .merge(this.cachedWorkspaceConfig); 32 | 33 | this.doWriteConfiguration(target, value, options) // _______ 34 | .then(|| null, 35 | || { 36 | return if options.donotNotifyError {TPromise.wrapError(error)} else {this.onError(error, target, value)}; 37 | }); 38 | 39 | angular.module("AngularAppModule") 40 | // _______ 41 | .constant("API_URL", "http://localhost:8080/api"); 42 | 43 | 44 | // _______ 45 | Observable.of(process) 46 | // _______ 47 | .merge(Observable.never()) 48 | // _______ 49 | .takeUntil(if throwOnError {errors.flatMap(Observable.throw)} else {errors}) 50 | .takeUntil(exit); 51 | 52 | -------------------------------------------------------------------------------- /tests/samples/comments/closure.rs: -------------------------------------------------------------------------------- 1 | 2 | call(|/*_______*/ row| {}); 3 | KEYPAD_NUMBERS.map(|num| ( // _______ 4 | 1 5 | )); 6 | 7 | 8 | const obj = A { 9 | f1: /* _______ */|| {}, 10 | f2: |/* _______ */| {}, 11 | f3: || /* _______ */ {}, 12 | f4: /* _______ */|/* _______ */| /* _______ */ {}, 13 | }; 14 | 15 | (/* _______ */|| {})(); 16 | (|/* _______ */| {})(); 17 | (|| /* _______ */ {})(); 18 | (/* _______ */|/* _______ */| /* _______ */ {})(); 19 | 20 | let commented = |/* first */ a /*argument*/, /* second*/ b: WithType /* argument*/, /* ignored */ _ | 21 | (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb); 22 | 23 | const fn1 = |/*_______, _______*/| doSomething(); 24 | const fn2 = |/*_______, _______*/| doSomething(anything); 25 | 26 | foo( 27 | | 28 | // _______ 29 | | {} 30 | ); 31 | 32 | const rootEpic = |actions, store| ( 33 | combineEpics(epics)(actions, store) 34 | // _______ 35 | .catch(|err, stream| { 36 | getLogger().error(err); 37 | return stream; 38 | }) 39 | ); 40 | -------------------------------------------------------------------------------- /tests/samples/comments/dangling.rs: -------------------------------------------------------------------------------- 1 | use std::{/* comment */}; 2 | 3 | macro_rules! m {/* comment */} 4 | macro_rules! m { (/* comment */) /* comment */ => /* comment */ {/* comment */} } 5 | 6 | macro m (/* comment */) /* comment */ {/* comment */} 7 | 8 | {/* comment */} 9 | 10 | f(/* comment */); 11 | 12 | f!/* comment */(/* comment */); 13 | f!/* comment */{/* comment */}; 14 | f!/* comment */[/* comment */]; 15 | 16 | f!([/* comment */]); 17 | f!({/* comment */}); 18 | f!((/* comment */)); 19 | 20 | f!(~[/* comment */]); 21 | f!(~{/* comment */}); 22 | f!(~(/* comment */)); 23 | 24 | [/* comment */]; 25 | (/* comment */); 26 | A /* comment */ {/* comment */}; 27 | 28 | if let A {/* comment */} | a(/* comment */) | [/* comment */] = (/* comment */) {} 29 | 30 | if 0 {/* comment */} 31 | if 0 {/* comment */}/* comment */else/* comment */ {/* comment */} 32 | if 0 {/* comment */}/* comment */else/* comment */if 0 {/* comment */} 33 | if 0 {/* comment */}/* comment */else/* comment */if /* comment */ let _ = 0 {/* comment */} 34 | 35 | match (/* comment */) { /* comment */ } 36 | 37 | fn a(/* comment */) /* comment */ {/* comment */} 38 | 39 | |/* comment */| 0; 40 | 41 | impl A {/* comment */} 42 | trait A {/* comment */} 43 | enum A {/* comment */} 44 | struct A(/* comment */) 45 | struct A{/* comment */} 46 | mod A {/* comment */} 47 | use A::{/* comment */} 48 | union A {/* comment */} 49 | 50 | A::; 51 | A::(/* comment */); 52 | 53 | type A: fn(/* comment */) where for A: for Fn(/* comment */) -> (/* comment */) 54 | 55 | #![/* comment */] 56 | #[/* comment */] 57 | struct A; 58 | 59 | #[/* comment */] 60 | #![/* comment */] 61 | struct A; 62 | 63 | #[/* comment */] 64 | #[/* comment */] 65 | #![/* comment */] 66 | struct A; 67 | 68 | #[/* comment */] 69 | #![/* comment */] 70 | #![/* comment */] 71 | struct A; 72 | 73 | #[/* comment */] 74 | #![/* comment */] 75 | #![/* comment */] 76 | #[/* comment */] 77 | struct A; 78 | 79 | #[/* comment */] 80 | #![/* comment */] 81 | #[/* comment */] 82 | #![/* comment */] 83 | struct A; -------------------------------------------------------------------------------- /tests/samples/comments/file.rs: -------------------------------------------------------------------------------- 1 | // This file only 2 | // has comments. This comment 3 | // should still exist 4 | // 5 | // when printed. 6 | 7 | /** 8 | * @typedef {DataDrivenMapping|ConstantMapping} Mapping 9 | */ 10 | /** 11 | * @typedef {Object.} ConfigurationMapping 12 | */ 13 | 14 | /** 15 | * @typedef {Function} D3Scale - a D3 scale 16 | * @property {Function} ticks 17 | * @property {Function} tickFormat 18 | */ 19 | // comment 20 | 21 | // comment 22 | -------------------------------------------------------------------------------- /tests/samples/comments/flow.rs: -------------------------------------------------------------------------------- 1 | loop { 2 | break /* _______ */; 3 | continue /* _______ */; 4 | } 5 | 6 | 'loop: loop { 7 | break /* _______ */ 'loop; 8 | break 'loop /* _______ */; 9 | continue /* _______ */ 'loop; 10 | continue 'loop /* _______ */; 11 | } 12 | 13 | 14 | return ( 15 | // _______ 16 | !!x 17 | ); 18 | 19 | return 1337; // _______ 20 | 21 | return ( 22 | // _______ 23 | 42 24 | ) && 84; 25 | 26 | return ( 27 | // _______ 28 | 42 29 | ) * 84; 30 | 31 | return if ( 32 | // _______ 33 | 42 34 | ) {1} else {2}; 35 | 36 | return if ( 37 | // _______ 38 | 42 39 | ) * 3 { 1 } else { 2 }; 40 | 41 | return ( 42 | // _______ 43 | a 44 | )(); 45 | 46 | return ( 47 | // _______ 48 | a.b 49 | ).c; 50 | 51 | return ( 52 | // _______ 53 | a 54 | ).b.c 55 | 56 | return ( 57 | // _______ 58 | afn.b() 59 | ).c.d() 60 | 61 | return ( 62 | // _______ 63 | if a.b() * 3 + 4 + (if ("a`hi`", 1) { 1 } else {1}) {} else {1} 64 | ) 65 | 66 | return ( // _______ 67 | a, b 68 | ); 69 | 70 | return ( 71 | // _______ 72 | a 73 | ); 74 | 75 | return ( 76 | /* _______ */ 42 77 | ) || 42; 78 | 79 | return observableFromSubscribeFunction() 80 | // _______ 81 | // _______ 82 | .debounceTime(debounceInterval); 83 | 84 | return A { 85 | // _______ 86 | bar: baz() + 1 87 | }; 88 | -------------------------------------------------------------------------------- /tests/samples/comments/functions.rs: -------------------------------------------------------------------------------- 1 | 2 | fn a(/* _______ */) {} // _______ 3 | fn b() {} // _______ 4 | fn c(/* _______ */ argA, argB, argC) {} // _______ 5 | fn a(a /*_______*/) {} 6 | fn b(a /*_______*/ 7 | ) {} 8 | fn d( 9 | a /*_______*/, 10 | b /*_______*/, 11 | c /*_______*/, 12 | d /*_______*/ 13 | ) {} 14 | fn d( 15 | a /*_______*/, 16 | b /*_______*/, 17 | c /*_______*/, 18 | d /*_______*/ 19 | ) /*_______*/ {} 20 | // prettier-ignore 21 | fn c(a /*_______*/ 22 | ) {} 23 | // prettier-ignore 24 | fn d( 25 | a /*_______*/, 26 | b /*_______*/, 27 | c /*_______*/, 28 | d /*_______*/ 29 | ) {} 30 | // prettier-ignore 31 | fn e( 32 | a /*_______*/, 33 | b /*_______*/, 34 | c /*_______*/, 35 | d /*_______*/ 36 | ) {} /* _______*/ 37 | 38 | fn f1 /* _______ */() {} 39 | fn f2 (/* _______ */) {} 40 | fn f3 () /* _______ */ {} 41 | fn f4 /* _______ */(/* _______ */) /* _______ */ {} 42 | fn f5 /* _______ */(/* _______ */ a) {} 43 | fn f6 /* _______ */(a /* _______ */) {} 44 | fn f7 /* _______ */(/* _______ */ a) /* _______ */ {} -------------------------------------------------------------------------------- /tests/samples/comments/ignore.attr.rs: -------------------------------------------------------------------------------- 1 | const baseline = 1 + 1; 2 | 3 | fn no() { 4 | a( a ); #![rustfmt::skip] 5 | // _______ 6 | } 7 | 8 | #[rustfmt::skip] 9 | const a = A { 10 | b: 11 | "_______", 12 | }; 13 | 14 | fn f() { 15 | 1 + 1; 16 | #[no ] 17 | #![rustfmt::skip] 18 | fn f() { 19 | 1 + 1; 20 | } 21 | } -------------------------------------------------------------------------------- /tests/samples/comments/ignore.file.rs: -------------------------------------------------------------------------------- 1 | const unformatted= 1; 2 | 3 | #![rustfmt::skip] // a 4 | 5 | fn unformatted () { 6 | struct a { 7 | // b 8 | c 9 | } 10 | } -------------------------------------------------------------------------------- /tests/samples/comments/ignore.rs: -------------------------------------------------------------------------------- 1 | const baseline = 1 + 1; 2 | 3 | // prettier-ignore 4 | let x = 5 | "" + this.USE + " " + this.STRICT + ";\n" + 6 | this.filterPrefix() + 7 | "var fn=" + this.generateFunction("fn", "s,l,a,i") + 8 | extra + 9 | this.watchFns() + 10 | "return fn;"; 11 | 12 | // prettier-ignore 13 | const x = Matrix.create( 14 | 1, 0, 0, 15 | 0, 1, 0, 16 | 0, 0, 0 17 | ); 18 | 19 | // prettier-ignore 20 | const x = A { 21 | b: 22 | "_______", 23 | }; 24 | 25 | 26 | fn f() { 27 | a( a ); // prettier-ignore 28 | // _______ 29 | } 30 | 31 | // prettier-ignore 32 | console.error( 33 | "_______" + prompt + "_______" + 34 | "_______ _______" 35 | ); 36 | 37 | const response = A { 38 | // prettier-ignore 39 | a: "Turn on the lights", 40 | intent: "lights", 41 | }; 42 | 43 | verylongidentifierthatwillwrap123123123123123( 44 | a.b 45 | // prettier-ignore 46 | // _______ 47 | .c 48 | ); 49 | 50 | call( 51 | // _______ 52 | a. 53 | // prettier-ignore 54 | b 55 | ) 56 | 57 | call( 58 | a( 59 | /* 60 | _______ 61 | */ 62 | 1, 63 | 2.0000, 3 64 | ) 65 | // prettier-ignore 66 | .c 67 | ) 68 | 69 | #[attr] 70 | // prettier-ignore 71 | const foo = 1 + 1; 72 | 73 | 74 | 75 | const A { 76 | // prettier-ignore 77 | bar : a, 78 | } = foo 79 | 80 | const A { 81 | a, 82 | // prettier-ignore 83 | bar2 : a, 84 | } = foo 85 | 86 | /* _______ */ 87 | const A { 88 | // prettier-ignore 89 | bar3 : a, // _______ 90 | } = foo 91 | 92 | const A { 93 | // prettier-ignore 94 | bar4 : a, /* _______ */ 95 | } = foo 96 | 97 | const A { 98 | // prettier-ignore 99 | bar5 : /* _______ */ a, 100 | } = foo 101 | 102 | const A { 103 | // prettier-ignore 104 | .. 105 | } = foo 106 | 107 | const A { 108 | baz: A { 109 | // prettier-ignore 110 | foo2: [a, b, c] 111 | }, 112 | // prettier-ignore 113 | bar7 : a, 114 | } = foo 115 | 116 | -------------------------------------------------------------------------------- /tests/samples/comments/imports.rs: -------------------------------------------------------------------------------- 1 | use list::{ 2 | // Some item 3 | SomeItem /* Comment */, /* Another item */ AnotherItem /* Another Comment */, // Last Item 4 | LastItem 5 | }; 6 | use test::{ Other /* C */ , /* A */ self /* B */ }; 7 | use {/* Pre-comment! */ 8 | Foo, Bar /* comment */}; -------------------------------------------------------------------------------- /tests/samples/comments/macro.rs: -------------------------------------------------------------------------------- 1 | a!(~ " { } "); 2 | a!(~ // 1 3 | ); 4 | a!(~ { // 2 5 | }); 6 | 7 | cfg_if::cfg_if! { 8 | if #[attr] { 9 | if 0 { 10 | } else { 11 | // ERROR! 12 | } 13 | } 14 | } 15 | 16 | a! { 17 | if #[attr] { 18 | // ERROR! 19 | } 20 | } 21 | 22 | x! {~ { 23 | // ERROR! 24 | } 25 | } -------------------------------------------------------------------------------- /tests/samples/comments/multiple.rs: -------------------------------------------------------------------------------- 1 | /* _______ */ /* _______ */ /* _______ */ a; 2 | a; /* _______ */ /* _______ */ /* _______ */ 3 | a // _______ 4 | a; 5 | /*1*//*2*//*3*/ 6 | b; 7 | 8 | a;/*1*//*2*//*3*/ 9 | b; 10 | 11 | a; 12 | /*1*//*2*//*3*/b; 13 | 14 | a; 15 | /* 16 | 1*//*2*//*3 17 | */ 18 | b; 19 | 20 | a;/* 21 | 1*//*2*//*3 22 | */ 23 | b; 24 | 25 | a;/* 26 | 1*//*2*//*3 27 | */b; 28 | 29 | a; 30 | /*1*//*2*/ 31 | /*3*/ 32 | b; 33 | 34 | a;/*1*//*2*/ 35 | /*3*/ 36 | b; 37 | 38 | a; 39 | /*1*//*2*/ 40 | /*3*/b; 41 | 42 | a; 43 | /* 44 | 1*//*2*/ 45 | /*3 46 | */ 47 | b; 48 | 49 | a;/* 50 | 1*//*2*/ 51 | /*3 52 | */ 53 | b; 54 | 55 | a;/* 56 | 1*//*2*/ 57 | /*3 58 | */b; 59 | 60 | a; 61 | /*1*/ 62 | /*2*//*3*/ 63 | b; 64 | 65 | a;/*1*/ 66 | /*2*//*3*/ 67 | b; 68 | 69 | a; 70 | /*1*/ 71 | /*2*//*3*/b; 72 | 73 | a; 74 | /* 75 | 1*/ 76 | /*2*//*3 77 | */ 78 | b; 79 | 80 | a;/* 81 | 1*/ 82 | /*2*//*3 83 | */ 84 | b; 85 | 86 | a;/* 87 | 1*/ 88 | /*2*//*3 89 | */b; 90 | 91 | use foo; /* 92 | 14 93 | */ /* 1 94 | 10 95 | */ /*/ 13 */ 96 | /* 97 | 9 98 | ****/ 99 | use bar; 100 | 101 | x; /* 102 | 1 */ /* 2 */ 103 | 104 | y 105 | 106 | x; /*1*//*2*/ 107 | y; 108 | 109 | 110 | /** 1 - OUTER DOC */ 111 | 112 | /* 2 - COMMENT */ 113 | 114 | /*! 3 - INNER DOC */ 115 | 116 | /*! 4 - INNER DOC */ 117 | 118 | /* 5A - COMMENT */ /** 119 | * 5B - OUTER DOC 120 | */ /** 121 | * 5C - OUTER DOC 122 | */ -------------------------------------------------------------------------------- /tests/samples/comments/parens.rs: -------------------------------------------------------------------------------- 1 | !x; 2 | !(x /* 0 */); 3 | !(/* 1 */ x); 4 | !( 5 | /* 2 */ 6 | x 7 | ); 8 | !( 9 | x 10 | /* 3 */ 11 | ); 12 | !( 13 | x // 4 14 | ); 15 | 16 | !(x + y); 17 | !(x + y /* 5 */); 18 | !(/* 6 */ x + y); 19 | a!(!(/* 6 */ x + y)); 20 | !( 21 | /* 7 */ 22 | x + y 23 | ); 24 | !( 25 | x + y 26 | /* 8 */ 27 | ); 28 | !( 29 | x + y // 9 30 | ); 31 | 32 | !(x || y); 33 | !(/* 10 */ x || y); 34 | !(x || y /* 11 */); 35 | !( 36 | /* 12 */ 37 | x || y 38 | ); 39 | !( 40 | x || y 41 | /* 13 */ 42 | ); 43 | !( 44 | x || y // 14 45 | ); 46 | 47 | ![1, 2, 3]; 48 | !([1, 2, 3] /* 15 */); 49 | !(/* 16 */ [1, 2, 3]); 50 | !( 51 | /* 17 */ 52 | [1, 2, 3] 53 | ); 54 | !( 55 | [1, 2, 3] 56 | /* 18 */ 57 | ); 58 | !( 59 | [1, 2, 3] // 19 60 | ); 61 | 62 | !A { a: 1, b: 2 }; 63 | !(A { a: 1, b: 2 } /* 20 */); 64 | !(/* 21 */ A { a: 1, b: 2 }); 65 | !( 66 | /* 22 */ 67 | A { a: 1, b: 2 } 68 | ); 69 | !( 70 | A { a: 1, b: 2 } 71 | /* 23 */ 72 | ); 73 | !( 74 | A { a: 1, b: 2 } // 24 75 | ); 76 | 77 | !|| { 78 | return x; 79 | }; 80 | !( 81 | || { 82 | return x; 83 | } /* 25 */ 84 | ); 85 | !( 86 | /* 26 */ || { 87 | return x; 88 | } 89 | ); 90 | !( 91 | /* 27 */ 92 | || { 93 | return x; 94 | } 95 | ); 96 | !( 97 | || { 98 | return x; 99 | } 100 | /* 28 */ 101 | ); 102 | !( 103 | || { 104 | return x; 105 | } // 29 106 | ); 107 | 108 | !(x = y); 109 | !(x = y /* 30 */); 110 | !(/* 31 */ x = y); 111 | !( 112 | /* 32 */ 113 | x = y 114 | ); 115 | !( 116 | x = y 117 | /* 33 */ 118 | ); 119 | !( 120 | x = y // 34 121 | ); 122 | 123 | !x.y; 124 | !(x.y /* 35 */); 125 | !(/* 36 */ x.y); 126 | !( 127 | /* 37 */ 128 | x.y 129 | ); 130 | !( 131 | x.y 132 | /* 38 */ 133 | ); 134 | !( 135 | x.y // 39 136 | ); 137 | 138 | !x(); 139 | !(x() /* 40 */); 140 | !(/* 41 */ x()); 141 | !( 142 | /* 42 */ 143 | x() 144 | ); 145 | !( 146 | x() 147 | /* 43 */ 148 | ); 149 | !( 150 | x() // 44 151 | ); 152 | 153 | 154 | !(x, y); 155 | !(x, y /* 45 */); 156 | !(/* 46 */ x, y); 157 | !( 158 | /* 47 */ 159 | x, y 160 | ); 161 | !( 162 | x, y 163 | /* 48 */ 164 | ); 165 | !( 166 | x.y // 49 167 | ); 168 | 169 | !(|| 3); 170 | !(|| 3 /* 50 */); 171 | !(/* 51 */ || 3); 172 | !( 173 | /* 52 */ 174 | || 3 175 | ); 176 | !( 177 | || 3 178 | /* 53 */ 179 | ); 180 | !( 181 | || 3 // 54 182 | ); 183 | 184 | loop { 185 | !(yield x); 186 | !(yield x /* 55 */); 187 | !(/* 56 */ yield x); 188 | !( 189 | /* 57 */ 190 | yield x 191 | ); 192 | !( 193 | yield x 194 | /* 58 */ 195 | ); 196 | !( 197 | yield x // 59 198 | ); 199 | } 200 | 201 | async || { 202 | !(x.await); 203 | !(x.await /* 60 */); 204 | !(/* 61 */ x.await); 205 | !( 206 | /* 62 */ 207 | x.await 208 | ); 209 | !( 210 | x.await 211 | /* 63 */ 212 | ); 213 | !( 214 | x.await // 64 215 | ); 216 | }; 217 | 218 | Math.min( 219 | ( 220 | /* ______________________________________________________________ 221 | * _______________________________________________________________ 222 | * _______ */ 223 | document.body.scrollHeight - 224 | (window.scrollY + window.innerHeight) 225 | ) - devsite_footer_height, 226 | 0, 227 | ); 228 | -------------------------------------------------------------------------------- /tests/samples/comments/whitespace.rs: -------------------------------------------------------------------------------- 1 | /* 2 | 1 3 | */ 4 | /* 5 | 2 6 | */ 7 | /* 8 | 3 9 | */ 10 | /* 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 4 20 | */ 21 | 22 | /* 23 | 5a 5b 24 | */ 25 | /* 26 | 6 27 | */ 28 | /* 29 | 7a 7b 30 | */ 31 | /* 32 | 8a 8b 33 | */ 34 | 35 | /* 36 | VT4+2: 9 37 | */ 38 | /* 39 | FF4+2: 10 40 | */ 41 | /* 42 | 43 | 44 | 45 | 46 | CR4+2: 11 47 | */ 48 | /* 49 | ………… NEL4+2: 12 50 | */ 51 | /* 52 |      13a 13b 53 | */ 54 | /* 55 |      14 56 | */ 57 | /* 58 |      15a 15b 59 | */ 60 | 61 | /* 62 |   16 63 |   16 64 |    16 65 |   16 66 |     16 67 |    16 68 |     16 69 |   16 70 |     16 71 |     16 72 |      16 73 |    16 74 |      16 75 |     16 76 |      16 77 | */ 78 | 79 | 80 | /* */ /* 81 | 17a 82 | 17b 17c 83 |        17d 84 | */ 85 | /* */ /* 86 | 18a 87 | 18b 18c 88 |        18d 89 | */ -------------------------------------------------------------------------------- /tests/samples/common/chains.first-argument-expansion.rs: -------------------------------------------------------------------------------- 1 | setTimeout(|| { 2 | thing(); 3 | }, 500); 4 | 5 | ["a","b","c"].reduce(|item, thing| { 6 | return thing + " " + item; 7 | }, "letters:") 8 | 9 | func(|| { 10 | thing(); 11 | }, identifier); 12 | 13 | func(|| { 14 | thing(); 15 | }, this.props.timeout * 1000); 16 | 17 | func(|| { 18 | thing(); 19 | }, this.props.getTimeout()); 20 | 21 | func(|| { 22 | thing(); 23 | }, true); 24 | 25 | func(|| { 26 | thing(); 27 | }, null); 28 | 29 | func(|| { 30 | thing(); 31 | }, undefined); 32 | 33 | func(|| { 34 | thing(); 35 | }, piohjougou); 36 | 37 | func(|| { 38 | thing(); 39 | }, 1 || 3); 40 | 41 | func(|| { 42 | return thing() 43 | }, 1 || 3); 44 | 45 | func(|| { 46 | thing(); 47 | }, if something() { someOtherThing() } else { somethingElse(true, 0) }); 48 | 49 | func(|| { 50 | thing(); 51 | }, if something(longArgumentName, anotherLongArgumentName) { someOtherThing() } else { somethingElse(true, 0) }); 52 | 53 | func(|| { 54 | thing(); 55 | }, if something(longArgumentName, anotherLongArgumentName, anotherLongArgumentName, anotherLongArgumentName) { someOtherThing() } else { somethingElse(true, 0) }); 56 | 57 | compose(|a| { 58 | return a.thing; 59 | }, |b| b * b); 60 | 61 | somthing.reduce(|item, thing| { 62 | return thing.blah = item; 63 | }, {}) 64 | 65 | somthing.reduce(|item, thing| { 66 | return thing.push(item); 67 | }, []) 68 | 69 | reallyLongLongLongLongLongLongLongLongLongLongLongLongLongLongMethod(|f, g, h| { 70 | return f.pop(); 71 | }, true); 72 | 73 | func(|| { 74 | thing(); 75 | }, true, false); 76 | 77 | func(|| { 78 | thing(); 79 | }, A {yes: true, cats: 5}); 80 | 81 | compose(|a| { 82 | return a.thing; 83 | }, |b| { 84 | return b + ""; 85 | }); 86 | 87 | compose(|a| { 88 | return a.thing; 89 | }, |b| [1, 2, 3, 4, 5]); 90 | 91 | setTimeout( 92 | // _______ 93 | || { 94 | thing(); 95 | }, 96 | 500 97 | ); 98 | 99 | setTimeout(/* _______ */ || { 100 | thing(); 101 | }, 500); 102 | 103 | func(|args| { 104 | execute(args); 105 | }, |result| result && console.log("success")) 106 | 107 | beep.boop().baz("foo", 108 | A { 109 | some: A { 110 | thing: A { 111 | nested: true 112 | } 113 | } 114 | }, 115 | A { another: A { thing: true } }, 116 | || {}); 117 | 118 | 119 | db.collection("indexOptionDefault").createIndex(A { a: 1 }, A { 120 | indexOptionDefaults: true, 121 | w: 2, 122 | wtimeout: 1000 123 | }, |err| { 124 | test.equal(null, err); 125 | test.deepEqual(A { w: 2, wtimeout: 1000 }, commandResult.writeConcern); 126 | 127 | client.close(); 128 | done(); 129 | }); 130 | 131 | -------------------------------------------------------------------------------- /tests/samples/common/chains.last-argument-expansion.rs: -------------------------------------------------------------------------------- 1 | crate fn searchUsers(action) { 2 | return action.ofType(ActionTypes.SEARCHED_USERS) 3 | .map(|| action.payload.query) 4 | .filter(|| !!q) 5 | .switchMap(|| 6 | Observable.timer(800) // _____ 7 | .takeUntil(action.ofType(ActionTypes.CLEARED_SEARCH_RESULTS)) 8 | .mergeMap(|| Observable.merge( 9 | Observable.of(replace("?q={q}")), 10 | ajax.getJSON("https://api.github.com/search/users?q={q}") 11 | .map(|| res.items) 12 | .map(receiveUsers) 13 | )) 14 | ); 15 | }; 16 | 17 | bob.doL(|A { a, b}| something.a.a(A {})); 18 | 19 | (A { 20 | processors: [ 21 | require("autoprefixer", A { 22 | browsers: ["> 1%", "last 2 versions", "ie >= 11", "Firefox ESR"] 23 | }), 24 | require("postcss-url")(A { 25 | url: |url| if url.startsWith("/") || "".test(url) { url } else { "/static/${url}" } 26 | }) 27 | ] 28 | }); 29 | 30 | foo( 31 | | 32 | // _______ 33 | | {} 34 | ); 35 | 36 | a( 37 | SomethingVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong, 38 | [ 39 | A { 40 | SomethingVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong: 1 41 | } 42 | ] 43 | ); 44 | 45 | exports.examples = [ 46 | A { 47 | render: withGraphQLQuery( 48 | "node(1234567890){image{uri}}", 49 | |container, data| { 50 | 51 | } 52 | ) 53 | } 54 | ]; 55 | 56 | someReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReally.a([ 57 | [], 58 | // ______ 59 | [], 60 | ]); 61 | 62 | (|| {})(this, |__WEBPACK_EXTERNAL_MODULE_85__, __WEBPACK_EXTERNAL_MODULE_115__| { 63 | return /******/ (|modules| { // ______ 64 | 65 | /******/ }) 66 | /************************************************************************/ 67 | /******/ ([ 68 | /* 0 */ 69 | /***/ |module, exports, __webpack_require__| { 70 | 71 | /***/ }, 72 | /* 1 */ 73 | /***/ |module, exports, __webpack_require__| { 74 | 75 | /***/ }, 76 | /* 2 */ 77 | /***/ |module, exports, __webpack_require__| { 78 | 79 | /***/ } 80 | /******/ ]) 81 | }); 82 | 83 | func(first, second, third, fourth, fifth, aReallyLongArgumentsListToForceItToBreak, A { 84 | // ______ 85 | }) 86 | 87 | func(A { 88 | // ______ 89 | }) 90 | 91 | func( 92 | A {} // ______ 93 | ) 94 | 95 | func( 96 | A {} 97 | // ______ 98 | ) 99 | 100 | func( 101 | // ______ 102 | A {} 103 | ) 104 | 105 | someFunctionCallWithBigArgumentsAndACallback(thisArgumentIsQuiteLong, |cool| { 106 | return cool 107 | }) 108 | 109 | fn mySagas() { 110 | yield effects.takeEvery( 111 | rexpress.actionTypes.REQUEST_START, 112 | |A { id }| { 113 | console.log(id); 114 | yield rexpress.actions(store).writeHead(id, 400); 115 | yield rexpress.actions(store).end(id, "pong"); 116 | console.log("pong"); 117 | } 118 | ); 119 | } 120 | 121 | fn mySagas2() { 122 | return effects.takeEvery( 123 | rexpress.actionTypes.REQUEST_START, 124 | |A { id }| { 125 | console.log(id); 126 | } 127 | ); 128 | } 129 | 130 | const Broken = Beact.fdrwardRef(|A { 131 | children, 132 | // 1 133 | // 2 134 | title, 135 | hidden, 136 | // 3 137 | }, ref d| ( 138 | A {children} 139 | )); 140 | 141 | bob 142 | .doL(|A { a, b: A{ 143 | // comment 144 | }}| something 145 | .e 146 | .e(A {})) 147 | 148 | instantiate(game, [ 149 | transform([-0.7, 0.5, 0]), 150 | render_colored_diffuse(game.MaterialDiffuse, game.Meshes["monkey_flat"], [1, 1, 0.3, 1]), 151 | ]); 152 | 153 | const formatData = pipe( 154 | zip, 155 | map(|[ ref a, data ]| (A { 156 | nodeId: a.nodeId.toString(), 157 | ..attributeFromDataValue(a.attributeId, data) 158 | })), 159 | groupBy(prop("nodeId")), 160 | map(mergeAll), 161 | values 162 | ); 163 | 164 | const setProp = |y| (A { 165 | ..y, 166 | a: "very, very, very long very, very long text" 167 | }); 168 | 169 | const log = |y| { 170 | console.log("very, very, very long very, very long text") 171 | }; 172 | 173 | SuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLongCall(|err, result| { 174 | // comment 175 | }); 176 | 177 | func(one, two, three, four, five, six, seven, eig, is, this, too, long, no, []); 178 | func(one, two, three, four, five, six, seven, eig, is, this, too, long, yes, []); 179 | func(one, two, three, four, five, six, seven, eig, is, this, too, long, yes, [ 180 | // Comments 181 | ]); 182 | func(five, six, seven, eg, is, this, too, long, yes, [ 183 | // Comments 184 | ]); 185 | 186 | func(one, two, three, four, five, six, seven, g, is, this, too, long, no, A {}); 187 | func(one, two, three, four, five, six, seven, g, is, this, too, long, yes, A {}); 188 | func(one, two, three, four, five, six, seven, g, is, this, too, long, yes, A { 189 | // Comments 190 | }); 191 | 192 | foo( 193 | | 194 | one, 195 | two, 196 | three, 197 | four, 198 | five, 199 | six, 200 | seven, 201 | eight, 202 | nine, 203 | ten, 204 | eleven, 205 | twelve, 206 | thirteen, 207 | fourteen, 208 | | {}, 209 | ); 210 | 211 | const contentTypes = |tile, singleSelection| { 212 | return compute( 213 | | 214 | tile, 215 | searchString, 216 | filteredContentTypes, 217 | contentTypesArray, 218 | selectedGroup, 219 | singleSelection| { 220 | selectedGroup = (tile.state && tile.state.group) || selectedGroup; 221 | } 222 | ); 223 | }; 224 | -------------------------------------------------------------------------------- /tests/samples/common/destructuring.rs: -------------------------------------------------------------------------------- 1 | const [one, two @ null, three @ null] = arr; 2 | a = |[s @ 1,]| 1 3 | const A { children, .. } = this.props 4 | 5 | const A { user: A { firstName, lastName } } = this.props; 6 | 7 | const A { 8 | name: A { first, last }, 9 | organisation: A { address: A { street: orgStreetAddress, postcode: orgPostcode } } 10 | } = user; 11 | 12 | fn f(A { data: A { name } }) {} 13 | 14 | const UserComponent = |A { 15 | name: A { first, last }, 16 | organisation: A { address: A { street: orgStreetAddress, postcode: orgPostcode } }, 17 | }| { 18 | return 19 | }; 20 | 21 | const A { a, b, c, d: A { e } } = someObject; 22 | 23 | for A { data: A { message }} in b { 24 | } 25 | 26 | const obj = A { 27 | func: |id, A { blog: A { title } }| { 28 | return id + title; 29 | }, 30 | }; 31 | 32 | const A { foo, bar: bazAndSomething, quxIsLong } = someBigFunctionName("foo")("bar"); 33 | -------------------------------------------------------------------------------- /tests/samples/common/members.rs: -------------------------------------------------------------------------------- 1 | (if valid 2 | { helper.responseBody(this.currentUser)} 3 | else{helper.responseBody(this.defaultUser)}) 4 | .prop; 5 | 6 | const veryVeryVeryVeryVeryVeryVeryLong = doc.expandedStates[doc.expandedStates.length - 1]; 7 | const small = doc.expandedStates[doc.expandedStates.length - 1]; 8 | 9 | const promises = [ 10 | promise.resolve().then(console.log).catch(|err| { 11 | console.log(err) 12 | return null 13 | }), 14 | redis.fetch(), 15 | other.fetch(), 16 | ]; 17 | 18 | const promises2 = [ 19 | promise.resolve().veryLongFunctionCall().veryLongFunctionCall().then(console.log).catch(|err| { 20 | console.log(err) 21 | return null 22 | }), 23 | redis.fetch(), 24 | other.fetch(), 25 | ]; 26 | 27 | window.FooClient.setVars(A { 28 | locale: getFooLocale(A { page }), 29 | authorizationToken: data.token 30 | }).initVerify("foo_container"); 31 | 32 | window.something.FooClient.setVars(A { 33 | locale: getFooLocale(A { page }), 34 | authorizationToken: data.token 35 | }).initVerify("foo_container"); 36 | 37 | window.FooClient.something.setVars(A { 38 | locale: getFooLocale(A { page }), 39 | authorizationToken: data.token 40 | }).initVerify("foo_container"); 41 | 42 | (veryLongVeryLongVeryLong || e).prop; 43 | 44 | (veryLongVeryLongVeryLong || anotherVeryLongVeryLongVeryLong || veryVeryVeryLongError).prop; 45 | 46 | const x = A { 47 | ABC: "12345678901234567890123456789012345678901234567890123456789012345678901234567890" 48 | }; 49 | const a = classnames(A { 50 | aaaaaaaaaaaa: this.state.longLongLongLongLongLongLongLongLongTooLongProp 51 | }); 52 | 53 | const b = classnames(A { 54 | aaaaaaaaaaaa: this.state.longLongLongLongLongLongLongLongLongTooLongProp == true 55 | }); 56 | 57 | const c = classnames(A { 58 | aaaaaaaaaaaa: [ "foo", "bar", "foo", "bar", "foo", "bar", "foo", "bar", "foo" ] 59 | }); 60 | 61 | const d = classnames(A { 62 | aaaaaaaaaaaa: || {} 63 | }); 64 | 65 | const e = classnames(A { 66 | aaaaaaaaaaaa: || {} 67 | }); 68 | 69 | const f = classnames(A { 70 | aaaaaaaaaaaa: A{ foo: "bar", bar: "foo", foo: "bar", bar: "foo", foo: "bar" } 71 | }); 72 | 73 | const g = classnames(A { 74 | aaaaaaaaaaaa: longLongLongLongLongLongLongLongLongLongLongLongLongTooLongVar || 1337 75 | }); 76 | 77 | const h = A { foo: "bar", baz: r"Lorem 78 | ipsum" } 79 | -------------------------------------------------------------------------------- /tests/samples/issues/14.rs: -------------------------------------------------------------------------------- 1 | [10.00, 10.0, 10., 10]; -------------------------------------------------------------------------------- /tests/samples/issues/21/fn_comment.rs: -------------------------------------------------------------------------------- 1 | fn eof() {} 2 | // comment -------------------------------------------------------------------------------- /tests/samples/issues/21/fn_fn.rs: -------------------------------------------------------------------------------- 1 | fn eof1() {} 2 | fn eof2() {} -------------------------------------------------------------------------------- /tests/samples/issues/21/fn_ln.rs: -------------------------------------------------------------------------------- 1 | fn eof() {} 2 | -------------------------------------------------------------------------------- /tests/samples/issues/21/ln_fn_ln.rs: -------------------------------------------------------------------------------- 1 | 2 | fn eof(){} 3 | -------------------------------------------------------------------------------- /tests/samples/issues/21/mod.rs: -------------------------------------------------------------------------------- 1 | mod eof {} -------------------------------------------------------------------------------- /tests/samples/issues/22.rs: -------------------------------------------------------------------------------- 1 | fn preserve_last_semicolon() { 2 | if let Some(left) = node.borrow().left.as_ref() { 3 | deque.push_back(left.clone()); 4 | }; 5 | if let Some(right) = node.borrow().right.as_ref() { 6 | deque.push_back(right.clone()); 7 | }; 8 | } 9 | 10 | fn a() { 11 | if let Ok(_) = lock.try_lock() {}; 12 | } 13 | 14 | fn b() { 15 | let lock = std::sync::Mutex::new(10); 16 | match lock.try_lock() { 17 | Ok(_) => {} 18 | Err(_) => {} 19 | }; 20 | match lock.try_lock() { 21 | Ok(_) => {} 22 | Err(_) => {} 23 | }; 24 | } 25 | 26 | fn c() { 27 | if let Ok(_) = lock.try_lock() {}; 28 | // comment 29 | } 30 | 31 | fn d() { 32 | if let Ok(_) = lock.try_lock() {}; // comment 33 | } 34 | 35 | fn e() { 36 | if let Ok(_) = lock.try_lock() {}/** comment */; 37 | } 38 | 39 | fn f() { 40 | if let Ok(_) = lock.try_lock() { 41 | 42 | } 43 | ; 44 | } 45 | 46 | fn g() { 47 | if let Ok(_) = lock.try_lock() { 48 | 49 | } 50 | // comment 51 | ; 52 | } 53 | 54 | fn h() { 55 | if let Ok(_) = lock {}; 56 | if let Ok(_) = lock {}; 57 | } 58 | 59 | fn i() { 60 | match lock {}; 61 | match lock {}; 62 | } 63 | 64 | fn inner_attr() { 65 | if let Ok(_) = lock.try_lock() {}; 66 | #![attr] 67 | } -------------------------------------------------------------------------------- /tests/samples/issues/25.rs: -------------------------------------------------------------------------------- 1 | #[ generator( yield( i32 ) )] 2 | fn nums() { 3 | yield_!(3); 4 | } 5 | 6 | // some extra samples to track changes 7 | #[ 8 | // 0 9 | generator 10 | // 1 11 | ( 12 | // 2 13 | yield 14 | // 3 15 | ( 16 | // 4 17 | i32 18 | // 5 19 | ) 20 | // 6 21 | ) 22 | // 7 23 | ] 24 | 25 | // non-conventional syntax (does not format) 26 | #[ #[a] generator( #[b] yield( #[c] i32 ))] 27 | #[generator (a( #[generator(b(i32))] i32 ) ) ] 28 | #[generator (a( #[generator(yield(i32))] i32 ) ) ] 29 | #[generator (yield( #[generator(b(i32))] i32 ) ) ] 30 | #[generator (yield( #[generator(yield(i32))] i32 ) ) ] 31 | fn f() { 32 | yield_!(3); 33 | } 34 | 35 | // macros in attr (does not format) 36 | #[attr(foo!( ))] 37 | fn f() {} -------------------------------------------------------------------------------- /tests/samples/issues/nth-pass.rs: -------------------------------------------------------------------------------- 1 | // prettier for javascript cannot format those in one pass 2 | 3 | return ( 4 | // _______ 5 | 42 6 | ) * 84 + 2; 7 | return ( 8 | // _______ 9 | 42 10 | ) + 84 * 2; 11 | 12 | foo // foo 13 | // comment after parent 14 | .x 15 | .y 16 | // comment 1 17 | .bar() // comment after bar() 18 | // comment 2 19 | .foobar 20 | // comment after 21 | // comment 3 22 | .baz(x, y, z); 23 | 24 | let zzzz = expr? // comment after parent 25 | // comment 0 26 | .another??? // comment 1 27 | .another???? // comment 2 28 | .another? // comment 3 29 | .another?; 30 | 31 | [ 32 | a = b, 33 | 34 | c // 35 | ]; -------------------------------------------------------------------------------- /tests/samples/macros/cfg_if.rs: -------------------------------------------------------------------------------- 1 | [ 2 | cfg_if! { if #[cfg(def)]{ use std; 0 } }, 3 | cfg_if! { if #[cfg(def)]{ use std; 0 } else { 1 } }, 4 | cfg_if! { if #[cfg(abc)]{ 0 } else { 1 } }, 5 | cfg_if! { if #[cfg(abc)]{ 0 } else if #[cfg(def)] { 1 } }, 6 | cfg_if! { if #[cfg(abc)]{ 0 } else if #[cfg(def)] { 1 } else { 0 } }, 7 | 8 | cfg_if! {}, 9 | cfg_if! { // comment 10 | if #[cfg(abc)] { 0 } }, 11 | cfg_if! { 12 | if #[cfg(abc)] { 13 | /// comment 14 | /// comment 15 | /// comment 16 | struct A{ 17 | //! comment 18 | a: u8 19 | } 20 | } }, 21 | cfg_if! { 22 | if #[cfg(abc)] { 23 | struct A{ 24 | //! comment 25 | // comment 26 | /// comment 27 | a: u8 28 | } 29 | } }, 30 | cfg_if! { 31 | if #[cfg(abc)] { 32 | struct A{ 33 | /// comment 34 | a: u8 35 | } 36 | } 37 | }, 38 | cfg_if! { 39 | if #[cfg(abc)] { 40 | struct A{ 41 | //! comment 42 | } 43 | } 44 | }, 45 | cfg_if! { 46 | if #[cfg(abc)] { 47 | struct A{ 48 | /// comment 49 | } 50 | } 51 | }, 52 | cfg_if! { if true{} } 53 | ] -------------------------------------------------------------------------------- /tests/samples/macros/if_chain.rs: -------------------------------------------------------------------------------- 1 | [ 2 | if_chain! { 3 | if let Some(a) = b; 4 | if let Err(a) = b; 5 | let (a, b) = c; 6 | if 1 + 2; 7 | then { d=0; } 8 | }, 9 | if_chain! { 10 | then { d=0; } 11 | }, 12 | if_chain! { 13 | then { d=0; } 14 | else { d!(); } 15 | }, 16 | if_chain! { 17 | if let A::B | A::C = D; 18 | then { 0 } else { 1 } 19 | }, 20 | if_chain! { 21 | let Ok(a) | Err(b) = c; 22 | then { d!(); } 23 | else { d!(); } 24 | }, 25 | if_chain! { 26 | if 1 + 1; 27 | let a: u32 = 3; 28 | 29 | then { d!(); } 30 | else { d!(); } 31 | } 32 | ] -------------------------------------------------------------------------------- /tests/samples/macros/matches.rs: -------------------------------------------------------------------------------- 1 | [ 2 | matches!(1 + 1, Some(_) ), 3 | matches!(1 + 1, Some(_) | None if 1 + 1 == 2), 4 | matches!(1 + 1, | Some(_) | None if 1 + 1 == 2) 5 | ] -------------------------------------------------------------------------------- /tests/samples/styling/blockify.rs: -------------------------------------------------------------------------------- 1 | [ 2 | || 0, 3 | || match 0 {}, 4 | || if 0 {}, 5 | || loop {}, 6 | || const {}, 7 | || async {}, 8 | 9 | || -> T 0, 10 | || -> T match 0 {}, 11 | || -> T if 0 {}, 12 | || -> T loop {}, 13 | || -> T const {}, 14 | || -> T async {} 15 | ] -------------------------------------------------------------------------------- /tests/samples/styling/canInlineBlockBody.rs: -------------------------------------------------------------------------------- 1 | [ 2 | { if 0 { 0 } }, 3 | { if 0 { 0 } else { 0 } }, 4 | { while 0 { 0 } }, 5 | { unsafe { 0 } }, 6 | 7 | { 0; if 0 { 0 } }, 8 | { 0; if 0 { 0 } else { 0 } }, 9 | { 0; while 0 { 0 } }, 10 | { 0; unsafe { 0 } }, 11 | 12 | f(async {}), 13 | f(async { 1 }), 14 | f(async { 1; }), 15 | 16 | { async {} }, 17 | { async { 1 } }, 18 | { async { 1; } }, 19 | 20 | { 0; async {} }, 21 | { 0; async { 1 } }, 22 | { 0; async { 1; } }, 23 | 24 | if (0 as u8) < 1 {} else {}, 25 | { 0; if (0 as u8) < 1 {} else {} }, 26 | if (0 as u8) < 1 {} else if (0 as u8) < 1 {}, 27 | 28 | if 0 {} else { 0; }, 29 | if 0 {} else if 1 { 0; } else {}, 30 | if 0 {} else if 1 {} else { 0; }, 31 | 32 | if 0 { 0; } else {}, 33 | 34 | if 0 { 0; } else { 2 }, 35 | if 0 { 2 } else { 0; }, 36 | 37 | match 0 { 38 | 0 => 0, 39 | 0 => { 0 } 40 | }, 41 | 42 | f(if 0 { 1 } else { 2 }), 43 | f({0;}, if 0 { 1 } else { 2 }), 44 | 0 + (if 0 { 1 } else { 2 }), 45 | { 0 + (if 0 { 1 } else { 2 }) }, 46 | ({0;}) + (if 0 { 1 } else { 2 }), 47 | 48 | match 0 { 49 | 0 => break 0, 50 | 0 => (o = 0), 51 | 0 => match 0 {}, 52 | 0 => if 0 {} else {}, 53 | 0 => if 0 {}, 54 | }, 55 | 56 | || loop { 57 | match 0 { 58 | 0 => break 0, 59 | 0 => (o = 0), 60 | 0 => match 0 {}, 61 | 0 => if 0 {} else {}, 62 | 0 => if 0 {}, 63 | } 64 | } 65 | ] 66 | 67 | -------------------------------------------------------------------------------- /tests/samples/styling/needsParens.rs: -------------------------------------------------------------------------------- 1 | let (A {} | a() | []) = (); 2 | if let (A {} | a() | []) = () {} 3 | 4 | type A: B + C; 5 | type A: impl B + C; 6 | 7 | trait A = B + C; 8 | trait A = impl B + C; -------------------------------------------------------------------------------- /tests/samples/styling/needsSemi.rs: -------------------------------------------------------------------------------- 1 | fn f() { 2 | #[cfg(unix)] { 0 } 3 | #[cfg(windows)] { 1 } 4 | } -------------------------------------------------------------------------------- /tests/test.build.ts: -------------------------------------------------------------------------------- 1 | import { exec } from "node:child_process"; 2 | import { inspect, promisify } from "node:util"; 3 | import prettier from "prettier"; 4 | import { testBuilds } from "../ext/jinx-rust/scripts/utils/build"; 5 | // import * as plugin_esm from "../index.js"; 6 | import plugin from "../src/index"; 7 | 8 | // test esm import 9 | await promisify(exec)('node -e "import(`./index.js`)"'); 10 | 11 | testBuilds( 12 | plugin, 13 | { 14 | esm: await import("../index.js"), 15 | cjs: (await import("../index.cjs")).default, 16 | }, 17 | function formatWithPlugin(file, plugin) { 18 | try { 19 | return { 20 | ext: "rs", 21 | content: prettier.format(file.content, { 22 | parser: "jinx-rust", 23 | plugins: [plugin], 24 | printWidth: 80, 25 | tabWidth: 2, 26 | filepath: file.cmd, 27 | }), 28 | }; 29 | } catch (e) { 30 | return { 31 | ext: "rs", 32 | content: inspect(e, { showHidden: true, getters: true }), 33 | }; 34 | } 35 | }, 36 | ["tests/samples", "ext/jinx-rust/tests/samples"] 37 | ); 38 | -------------------------------------------------------------------------------- /tsconfig.base.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2020", // upper target changes property order 4 | 5 | // module 6 | "module": "ESNext", 7 | "moduleResolution": "Node", 8 | "esModuleInterop": true, 9 | 10 | // types 11 | "lib": ["ESNext"], 12 | "skipLibCheck": true, 13 | "skipDefaultLibCheck": true, 14 | 15 | // checks 16 | "allowUnusedLabels": true, 17 | "exactOptionalPropertyTypes": true, 18 | "noFallthroughCasesInSwitch": true, 19 | 20 | // strict 21 | "strict": true, 22 | "noImplicitAny": false, 23 | "strictFunctionTypes": false, 24 | "strictPropertyInitialization": false, 25 | 26 | // Project 27 | "composite": true, 28 | "isolatedModules": true 29 | }, 30 | "ts-node": { 31 | "esm": true, 32 | "swc": true, 33 | "experimentalSpecifierResolution": "node" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.base.json", 3 | "include": ["src"], 4 | "compilerOptions": { 5 | // "declaration": true, 6 | // "declarationDir": "dist", 7 | // "emitDeclarationOnly": true, 8 | 9 | // "outDir": "dist", 10 | // "rootDir": "src", 11 | // "rootDirs": ["src", "dist"], 12 | "composite": false, 13 | "isolatedModules": false, 14 | "preserveConstEnums": false 15 | // "removeComments": false 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.base.json", 3 | "include": ["src"], 4 | "compilerOptions": { 5 | "types": ["prettier", "jinx-rust"], 6 | "rootDir": "src" 7 | } 8 | } 9 | --------------------------------------------------------------------------------