Skip to content

Commit b47e552

Browse files
author
James Brundage
committed
Adding Inline TypeScript Support (#45)
1 parent 3d5a5fd commit b47e552

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<#
2+
.SYNOPSIS
3+
TypeScript Inline PipeScript Transpiler.
4+
.DESCRIPTION
5+
Transpiles TypeScript with Inline PipeScript into TypeScript.
6+
7+
Multiline comments with /*{}*/ will be treated as blocks of PipeScript.
8+
9+
Multiline comments can be preceeded or followed by 'empty' syntax, which will be ignored.
10+
11+
This is so that Inline PipeScript can be used with operators, and still be valid TypeScript syntax.
12+
13+
The TypeScript Inline Transpiler will consider the following syntax to be empty:
14+
15+
* ```undefined```
16+
* ```null```
17+
* ```""```
18+
* ```''```
19+
#>
20+
[ValidateScript({
21+
$cmdInfo = $_
22+
if ($cmdInfo.Source -match '\.ts)$') {
23+
return $true
24+
}
25+
return $false
26+
})]
27+
param(
28+
# The command information. This will include the path to the file.
29+
[Parameter(Mandatory,ValueFromPipeline)]
30+
$CommandInfo
31+
)
32+
33+
begin {
34+
# We start off by declaring a number of regular expressions:
35+
$startComment = '/\*' # * Start Comments ```\*```
36+
$endComment = '\*/' # * End Comments ```/*```
37+
$Whitespace = '[\s\n\r]{0,}'
38+
# * IgnoredContext ```String.empty```, ```null```, blank strings and characters
39+
$IgnoredContext = "(?<ignore>(?>$("undefined", "null", '""', "''" -join '|'))\s{0,}){0,1}"
40+
# * StartRegex ```$IgnoredContext + $StartComment + '{' + $Whitespace```
41+
$startRegex = "(?<PSStart>${IgnoredContext}${startComment}\{$Whitespace)"
42+
# * EndRegex ```$whitespace + '}' + $EndComment + $ignoredContext```
43+
$endRegex = "(?<PSEnd>$Whitespace\}${endComment}\s{0,}${IgnoredContext})"
44+
45+
$sourcePattern = [Regex]::New("(?>$(
46+
$startRegex, $endRegex -join ([Environment]::NewLine + '|' + [Environment]::NewLine)
47+
))", "IgnoreCase, IgnorePatternWhitespace", "00:00:05")
48+
}
49+
50+
process {
51+
52+
$fileInfo = $commandInfo.Source -as [IO.FileInfo]
53+
$fileText = [IO.File]::ReadAllText($fileInfo.Fullname)
54+
55+
.>PipeScript.Inline -SourceFile $CommandInfo.Source -SourceText $fileText -SourcePattern $sourcePattern
56+
}

0 commit comments

Comments
 (0)