Extend PowerShell highlighting and add a showcase #26
Openkahwee(GitHub profile, opens in a new tab)wants to merge 2 commits into
main fromrefs/pull/26/headopened - docs/guides/performance.md line 21OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -8,12 +8,14 @@8899 ## Bundle profiles101011-`pnpm run size` builds seventeen browser profiles with esbuild and measures minified, gzip, and Brotli bytes independently. It also checks that helper, adapter, and selective language imports retain only the requested modules.11+`pnpm run size` builds nineteen browser profiles with esbuild and measures minified, gzip, and Brotli bytes independently. It also checks that helper, adapter, and selective language imports retain only the requested modules.12121313 | Profile | Registered languages | Current gzip | CI budget |1414 | --- | --- | ---: | ---: |1515 | Core | None | 1.82 KB | 2.0 KB |1616 | TSX | TSX | 4.26 KB | 4.35 KB |1717 | Octane | TypeScript plus Octane MDX adapter | 5.59 KB | 5.7 KB |1818 | Docs | CSS, HTML, JS, JSON, JSX, Markdown, Shell, TS, TSX | 6.20 KB | 6.3 KB |19-| All | All 30 definitions | 10.77 KB | 10.9 KB |19+| Swift | Swift | 3.36 KB | 3.55 KB |20+| PowerShell | PowerShell | 3.27 KB | 3.55 KB |21+| All | All 32 definitions | 12.43 KB | 12.7 KB |src/languages/swift.ts lines 64 to 67OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +47,21 @@47+ }48+ return ranges49+}50+51+function commentEnd(code: string, start: number) {52+ let depth = 153+ let index = start + 254+ while (index < code.length && depth) {55+ if (code.startsWith('/*', index)) { depth++; index += 2 }56+ else if (code.startsWith('*/', index)) { depth--; index += 2 }57+ else index++58+ }59+ return index60+}61+62+function stringEnd(code: string, start: number, depth = 0): number {63+ let index = start64+ while (code[index] === '#') index++65+ const hashes = code.slice(start, index)66+ const regex = Boolean(hashes) && code[index] === '/'67+ if (code[index] !== '"' && !regex) return starttest/showcases/Get-StationReport.ps1 line 10OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +1,10 @@1+#Requires -Version 7.42+<# Build typed records, then shape a pipeline for display.3+ Quotes and $variables in this comment stay quiet. #>4+function Get-StationReport {5+ [CmdletBinding()]6+ param(7+ [Parameter(Mandatory)]8+ [ValidateSet('coast', 'ridge')]9+ [string[]] $Station,10+ [int] $Limit = 5
- @@ -0,0 +1,8 @@1+import { defineLanguage, type TokenRange } from '../core.js'2+import { patternTokenizer } from '../internal/patterns.js'3+4+export const swift = defineLanguage({5+ name: 'swift',6+ tokenize: patternTokenizer([7+ { collect: collectSwiftLexicalRanges },8+ { className: 'meta', regex: /#(?:if|elseif|else|endif|available|unavailable|selector|keyPath|sourceLocation|warning|error|fileID|filePath|file|line|column|function)\b/g },@@ -0,0 +1,12 @@1+import { defineLanguage, type TokenRange } from '../core.js'2+import { patternTokenizer } from '../internal/patterns.js'3+4+export const swift = defineLanguage({5+ name: 'swift',6+ tokenize: patternTokenizer([7+ { collect: collectSwiftLexicalRanges },8+ { className: 'meta', regex: /#(?:if|elseif|else|endif|available|unavailable|selector|keyPath|sourceLocation|warning|error|fileID|filePath|file|line|column|function)\b/g },9+ { className: 'attr', regex: /@[A-Za-z_]\w*/g },10+ { className: 'variable', regex: /\$(?:\d+|[A-Za-z_]\w*)/g },11+ { className: 'literal', regex: /\b(?:true|false|nil)\b/g },12+ { className: 'keyword', regex: /\b(?:actor|any|as|associatedtype|async|await|borrowing|break|case|catch|class|consuming|continue|convenience|copy|default|defer|deinit|didSet|distributed|do|dynamic|each|else|enum|extension|fallthrough|fileprivate|final|for|func|get|guard|if|import|indirect|infix|init|inout|internal|in|is|isolated|lazy|let|mutating|nonisolated|nonmutating|open|operator|optional|override|package|postfix|precedencegroup|prefix|private|protocol|public|repeat|required|rethrows|return|self|set|some|static|struct|subscript|super|switch|throw|throws|try|typealias|unowned|var|weak|where|while|willSet)\b/g },@@ -0,0 +1,15 @@1+import { defineLanguage, type TokenRange } from '../core.js'2+import { patternTokenizer } from '../internal/patterns.js'3+4+export const swift = defineLanguage({5+ name: 'swift',6+ tokenize: patternTokenizer([7+ { collect: collectSwiftLexicalRanges },8+ { className: 'meta', regex: /#(?:if|elseif|else|endif|available|unavailable|selector|keyPath|sourceLocation|warning|error|fileID|filePath|file|line|column|function)\b/g },9+ { className: 'attr', regex: /@[A-Za-z_]\w*/g },10+ { className: 'variable', regex: /\$(?:\d+|[A-Za-z_]\w*)/g },11+ { className: 'literal', regex: /\b(?:true|false|nil)\b/g },12+ { className: 'keyword', regex: /\b(?:actor|any|as|associatedtype|async|await|borrowing|break|case|catch|class|consuming|continue|convenience|copy|default|defer|deinit|didSet|distributed|do|dynamic|each|else|enum|extension|fallthrough|fileprivate|final|for|func|get|guard|if|import|indirect|infix|init|inout|internal|in|is|isolated|lazy|let|mutating|nonisolated|nonmutating|open|operator|optional|override|package|postfix|precedencegroup|prefix|private|protocol|public|repeat|required|rethrows|return|self|set|some|static|struct|subscript|super|switch|throw|throws|try|typealias|unowned|var|weak|where|while|willSet)\b/g },13+ { className: 'type', regex: /\b(?:actor|class|enum|protocol|struct|typealias)\s+([\p{L}_][\p{L}\p{N}_]*)/gu, group: 1 },14+ { className: 'type', regex: /\b(?:Any|AnyObject|Array|Bool|Character|Dictionary|Double|Float|Int(?:8|16|32|64)?|Never|Optional|Result|Self|Set|String|UInt(?:8|16|32|64)?|Void)\b/g },15+ { className: 'function', regex: /[\p{L}_][\p{L}\p{N}_]*(?=\s*\()/gu },@@ -0,0 +55,21 @@55+ let index = start + 256+ while (index < code.length && depth) {57+ if (code.startsWith('/*', index)) { depth++; index += 2 }58+ else if (code.startsWith('*/', index)) { depth--; index += 2 }59+ else index++60+ }61+ return index62+}63+64+function stringEnd(code: string, start: number, depth = 0): number {65+ let index = start66+ while (code[index] === '#') index++67+ const hashes = code.slice(start, index)68+ const regex = Boolean(hashes) && code[index] === '/'69+ if (code[index] !== '"' && !regex) return hashes ? -index : start70+ const quote = regex ? '/' : code.startsWith('"""', index) ? '"""' : '"'71+ index += quote.length72+ const close = quote + hashes73+ const escape = regex ? '\\' : '\\' + hashes74+ while (index < code.length) {75+ if (code.startsWith(close, index)) return index + close.length@@ -0,0 +1,10 @@1+import { defineLanguage, type TokenRange } from '../core.js'2+import { patternTokenizer } from '../internal/patterns.js'3+4+export const powershell = defineLanguage({5+ name: 'powershell',6+ aliases: ['pwsh', 'ps1'],7+ tokenize: patternTokenizer([8+ { collect: collectPowerShellLexicalRanges },9+ { className: 'literal', regex: /\$(?:true|false|null)\b/gi },10+ { className: 'variable', regex: /\$\{(?:`[\s\S]|[^}`])*\}|[$@](?:[\p{L}\p{N}_?]+:)?[\p{L}\p{N}_?]+|\$[$^]/gu },@@ -0,0 +1,12 @@1+import { defineLanguage, type TokenRange } from '../core.js'2+import { patternTokenizer } from '../internal/patterns.js'3+4+export const powershell = defineLanguage({5+ name: 'powershell',6+ aliases: ['pwsh', 'ps1'],7+ tokenize: patternTokenizer([8+ { collect: collectPowerShellLexicalRanges },9+ { className: 'literal', regex: /\$(?:true|false|null)\b/gi },10+ { className: 'variable', regex: /\$\{(?:`[\s\S]|[^}`])*\}|[$@](?:[\p{L}\p{N}_?]+:)?[\p{L}\p{N}_?]+|\$[$^]/gu },11+ { className: 'type', regex: /\[(?:[A-Za-z_]\w*\.)*[A-Za-z_]\w*(?:\[\])?\]/g },12+ { className: 'keyword', regex: /(?<![\w-])(?:begin|break|catch|class|clean|continue|data|do|dynamicparam|else|elseif|end|enum|exit|filter|finally|for|foreach|function|if|in|param|process|return|switch|throw|trap|try|until|using|while|workflow|parallel|sequence|inlinescript)(?![\w-])/gi },
- src/languages/powershell.ts line 30OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +10,21 @@10+ { className: 'variable', regex: /[$@](?:[\p{L}\p{N}_?]+:)?[\p{L}\p{N}_?]+|\$[$^]/gu },11+ { className: 'type', regex: /\[(?:[A-Za-z_]\w*\.)*[A-Za-z_]\w*(?:\[\])?\]/g },12+ { className: 'keyword', regex: /(?<![\w.-])(?:begin|break|catch|class|clean|continue|data|do|dynamicparam|else|elseif|end|enum|exit|filter|finally|for|foreach|function|if|in|param|process|return|switch|throw|trap|try|until|using|while|workflow|parallel|sequence|inlinescript)(?![\w-])/gi },13+ { className: 'function', regex: /\b(?:function|filter|class|enum)\s+([A-Za-z_][\w-]*)/gi, group: 1 },14+ { className: 'command', regex: /(?<![\w-])[A-Za-z]+-[A-Za-z][\w-]*\b/g },15+ { className: 'operator', regex: /-(?:(?:[ci])?(?:eq|ne|gt|ge|lt|le|like|notlike|match|notmatch|contains|notcontains|in|notin|replace|split)|and|or|xor|not|band|bor|bxor|bnot|shl|shr|join|isnot|is|as|f)\b/gi },16+ { className: 'property', regex: /(?<![\w-])-[A-Za-z][\w-]*\b/g },17+ { className: 'number', regex: /(?:(?<![\w.])|(?<=\.\.))(?:0[xX][\da-fA-F]+|0[bB][01]+|(?:\d+(?:\.(?!\.)\d*)?|\.\d+)(?:e[+-]?\d+)?)(?:u?[ylsn]|ul|us|uy|d)?(?:kb|mb|gb|tb|pb)?(?!\w)(?!\.(?!\.))/gi },18+ { className: 'function', regex: /\b[A-Za-z_]\w*(?=\s*\()/g },19+ { className: 'property', regex: /\.([A-Za-z_]\w*)/g, group: 1 },20+ { className: 'operator', regex: /\?\?=?|\?\.|::|\.\.|\+\+|--|&&|\|\||[+\-*/%=!<>|&]=?/g },21+ ]),22+})23+24+function collectPowerShellLexicalRanges(code: string) {25+ const ranges: Array<TokenRange> = []26+ for (let index = 0; index < code.length;) {27+ const start = index28+ let end = index29+ let className: TokenRange['className'] = 'string'30+ if (code[index] === '`') { index += 2; continue }
kahwee(GitHub profile, opens in a new tab) changed the title
kahwee(GitHub profile, opens in a new tab) changed the title
Sign in to join this conversation.
🦋 Changeset detected#
Latest commit: 25996c4fe8893d512e7f5fdbdccc4b5cdc29b341
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR