generated from KOLANICH/python_project_boilerplate.py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
56 lines (40 loc) · 1.66 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import typing
from pathlib import Path
from warnings import warn
warn("We have moved from M$ GitHub to https://codeberg.org/KOLANICH-libs/ClosureCompiler.py , read why on https://codeberg.org/KOLANICH/Fuck-GuanTEEnomo .")
from .enums import TypeInferMode
from .lowLevel import *
from .lowLevel import _optionsComponentTypes, _otherEssentialClasses
__all__ = ("SourcesMappingTU", "Compiler", "createCompilerOptions") + _optionsComponentTypes + _otherEssentialClasses
class ClosureCompilerErrror(RuntimeError):
__slots__ = ()
class Compiler:
__slots__ = ("compiler", "options")
def __init__(self, options: typing.Optional[CompilerOptions] = None) -> None:
if options is None:
options = createCompilerOptions()
self.options = options
self.compiler = None
@property
def _jsRoot(self):
prop = ji.reflectClass(self.compiler.__class__).getDeclaredField("jsRoot")
prop.setAccessible(True)
return prop.get(self.compiler)
def getBuiltInExterns(self):
return getBuiltInExterns(self.options.getEnvironment())
def __call__(self, sources: SourcesMappingTU, externs: typing.Optional[SourcesMappingTU] = None) -> Result:
return self.compile(sources, externs)
def compile(self, sources: SourcesMappingTU, externs: typing.Optional[SourcesMappingTU] = None) -> Result:
sources = convertSourcesMapping(sources)
builtinExterns = self.getBuiltInExterns()
if externs:
externs = convertSourcesMapping(externs)
else:
externs = []
self.compiler = ji.Compiler()
lowLevelRes = self.compiler.compile(
ji.ArrayList(externs + builtinExterns),
ji.ArrayList(sources),
self.options,
)
return Result.fromNativeResult(str(self.compiler.toSource()), lowLevelRes)