├── .gitattributes
├── .github
├── FUNDING.yml
├── ISSUE_TEMPLATE
│ └── custom.md
├── codeql
│ └── codeql-config.yml
└── workflows
│ ├── cmake-test-release-linux.yml
│ ├── cmake-test-release-win.yml
│ └── create-release.yml
├── .gitignore
├── .gitmodules
├── .travis.yml
├── .vscode
└── settings.json
├── 3rdParty_cleanup.bat
├── CODE_OF_CONDUCT.md
├── LICENSE
├── README.md
├── cleanup.bat
├── docs
├── MLIR_to_exe
│ └── test_wasm.html
├── VisualStudio
│ └── CustomTool
│ │ ├── tsc.props
│ │ ├── tsc.targets
│ │ └── tsc.xml
├── bugs
│ ├── array_of_ifaces_cast.ts
│ ├── bug14.ts
│ ├── bug21.ts
│ ├── generic_in_generic.ts
│ └── testFallThrough.ts
├── compiler-explorer
│ ├── etc
│ │ └── config
│ │ │ └── typescript.defaults.properties
│ ├── examples
│ │ └── typescript
│ │ │ └── default.ts
│ ├── infra
│ │ └── bin
│ │ │ └── yaml
│ │ │ └── typescript.yaml
│ ├── lib
│ │ ├── compilers
│ │ │ ├── _all.js
│ │ │ ├── argument-parsers.js
│ │ │ └── typescript.js
│ │ └── languages.js
│ └── webpack.config.esm.js
├── fix
│ ├── AddCompilerRT.cmake
│ ├── gc
│ │ ├── CMakeLists.txt
│ │ └── tests
│ │ │ └── CMakeLists.txt
│ └── llvm
│ │ └── cmake
│ │ └── modules
│ │ └── CrossCompile.cmake
├── fixes.txt
├── how
│ ├── cmake
│ │ └── gc_example
│ │ │ ├── CMakeLists.txt
│ │ │ ├── config_debug.bat
│ │ │ ├── config_llvm_debug.bat
│ │ │ ├── config_llvm_win_debug.bat
│ │ │ ├── config_release.bat
│ │ │ ├── dummy.cpp
│ │ │ ├── llvm_tool.cmake
│ │ │ ├── llvm_tool_win.cmake
│ │ │ ├── src
│ │ │ └── main.ts
│ │ │ └── typescript.cmake
│ ├── cmake_vulkan
│ │ ├── CMakeLists.txt
│ │ ├── config_debug.bat
│ │ ├── config_llvm_debug.bat
│ │ ├── config_llvm_win_debug.bat
│ │ ├── config_release.bat
│ │ ├── dummy.cpp
│ │ ├── llvm_tool.cmake
│ │ ├── llvm_tool_win.cmake
│ │ ├── native
│ │ │ ├── cube.frag.inc
│ │ │ ├── cube.vert.inc
│ │ │ ├── linmath.h
│ │ │ ├── lunarg.ppm.h
│ │ │ ├── vulkan.win32.cpp
│ │ │ ├── window.win32.cpp
│ │ │ └── window.win32.h
│ │ ├── src
│ │ │ ├── application.ts
│ │ │ ├── appwindow.ts
│ │ │ ├── main.ts
│ │ │ └── window.win32.d.ts
│ │ └── typescript.cmake
│ ├── cmake_winapp
│ │ ├── .vscode
│ │ │ └── launch.json
│ │ ├── CMakeLists.txt
│ │ ├── config_debug.bat
│ │ ├── config_llvm_debug.bat
│ │ ├── config_llvm_win_debug.bat
│ │ ├── config_release.bat
│ │ ├── dummy.cpp
│ │ ├── llvm_tool.cmake
│ │ ├── llvm_tool_win.cmake
│ │ ├── native
│ │ │ ├── window.win32.cpp
│ │ │ └── window.win32.h
│ │ ├── src
│ │ │ ├── application.ts
│ │ │ ├── appwindow.ts
│ │ │ ├── main.ts
│ │ │ └── window.win32.d.ts
│ │ └── typescript.cmake
│ └── wasm
│ │ ├── built-libclang_rt.builtins-wasm32.txt
│ │ ├── test
│ │ ├── 1.bat
│ │ ├── index.html
│ │ └── test_wasm.ps1
│ │ └── wasm
│ │ ├── hello.wasm
│ │ ├── index.html
│ │ ├── tsc_wasm.bat
│ │ └── tsc_wasm_emscripten.bat
├── not_impl
│ ├── not_impl12.ts
│ ├── not_impl13.ts
│ ├── not_impl15.ts
│ ├── not_impl19.ts
│ ├── not_impl20.ts
│ ├── not_impl26.ts
│ ├── not_impl27.ts
│ ├── not_impl28.ts
│ ├── not_impl30.ts
│ ├── not_impl31.ts
│ ├── not_impl5.ts
│ ├── not_impl7.ts
│ └── not_impl9.ts
└── todo.txt
├── prepare_3rdParty.bat
├── prepare_3rdParty_debug.sh
├── prepare_3rdParty_lldb.bat
├── prepare_3rdParty_release.sh
├── prepare_3rdParty_wasm_debug.sh
├── scripts
├── build_gc_debug.sh
├── build_gc_debug_ninja.bat
├── build_gc_debug_vs.bat
├── build_gc_release.sh
├── build_gc_release_ninja.bat
├── build_gc_release_vs.bat
├── build_lldb_debug.bat
├── build_lldb_release.bat
├── build_llvm_debug.sh
├── build_llvm_debug_ninja.bat
├── build_llvm_debug_vs.bat
├── build_llvm_release.sh
├── build_llvm_release_ninja.bat
├── build_llvm_release_vs.bat
├── build_llvm_wasm_debug.bat
├── build_llvm_wasm_debug.sh
├── build_llvm_wasm_release.bat
├── build_llvm_wasm_release.sh
├── config_lldb_debug.bat
├── config_lldb_release.bat
├── config_llvm_debug.sh
├── config_llvm_debug_ninja.bat
├── config_llvm_debug_vs.bat
├── config_llvm_debug_vs19.bat
├── config_llvm_debug_vs_clangcl.bat
├── config_llvm_debug_vs_intel.bat
├── config_llvm_release.sh
├── config_llvm_release_ninja.bat
├── config_llvm_release_vs.bat
├── config_llvm_wasm_debug.bat
├── config_llvm_wasm_debug.sh
├── config_llvm_wasm_release.bat
├── config_llvm_wasm_release.sh
└── separate_debug_info.sh
├── tag.bat
├── tag_del.bat
├── tsc.code-workspace
└── tsc
├── CMakeLists.txt
├── CMakePresets.json
├── build_tsc_debug-test.bat
├── build_tsc_debug-unittests.bat
├── build_tsc_debug.bat
├── build_tsc_debug.sh
├── build_tsc_defaultlib_debug.bat
├── build_tsc_release-test.bat
├── build_tsc_release-test.sh
├── build_tsc_release.bat
├── build_tsc_release.sh
├── cmake
└── config_macros.cmake
├── config_tsc_debug.bat
├── config_tsc_debug.sh
├── config_tsc_release.bat
├── config_tsc_release.sh
├── include
├── .vscode
│ ├── c_cpp_properties.json
│ └── settings.json
├── CMakeLists.txt
└── TypeScript
│ ├── AsyncDialectTranslation.h
│ ├── CMakeLists.txt
│ ├── Config.h
│ ├── DOM.h
│ ├── DataStructs.h
│ ├── Defines.h
│ ├── DiagnosticHelper.h
│ ├── Helper.h
│ ├── LowerToLLVM
│ ├── AnyLogic.h
│ ├── AssertLogic.h
│ ├── CastLogicHelper.h
│ ├── CodeLogicHelper.h
│ ├── ConvertLogic.h
│ ├── DefaultLogic.h
│ ├── LLVMCodeHelper.h
│ ├── LLVMCodeHelperBase.h
│ ├── LLVMDebugInfo.h
│ ├── LLVMDebugInfoFixer.h
│ ├── LLVMRTTIHelperVC.h
│ ├── LLVMRTTIHelperVCLinux.h
│ ├── LLVMRTTIHelperVCLinuxConst.h
│ ├── LLVMRTTIHelperVCWin32.h
│ ├── LLVMRTTIHelperVCWin32Const.h
│ ├── LLVMTypeConverterHelper.h
│ ├── LocationHelper.h
│ ├── OptionalLogicHelper.h
│ ├── ThrowLogic.h
│ ├── TypeConverterHelper.h
│ ├── TypeHelper.h
│ ├── UnaryBinLogicalOrHelper.h
│ └── UndefLogicHelper.h
│ ├── LowerToLLVMLogic.h
│ ├── MLIRGen.h
│ ├── MLIRLogic
│ ├── MLIRCodeLogic.h
│ ├── MLIRDebugInfoHelper.h
│ ├── MLIRDeclarationPrinter.h
│ ├── MLIRDefines.h
│ ├── MLIRGenContext.h
│ ├── MLIRGenContextDefines.h
│ ├── MLIRGenStore.h
│ ├── MLIRHelper.h
│ ├── MLIRLocationGuard.h
│ ├── MLIRNamespaceGuard.h
│ ├── MLIRPrinter.h
│ ├── MLIRRTTIHelperVC.h
│ ├── MLIRRTTIHelperVCLinux.h
│ ├── MLIRRTTIHelperVCWin32.h
│ ├── MLIRTypeCore.h
│ ├── MLIRTypeHelper.h
│ ├── MLIRTypeIterator.h
│ ├── MLIRValueGuard.h
│ └── TypeOfOpHelper.h
│ ├── ObjDumper.h
│ ├── Pass
│ ├── AliasPass.h
│ ├── DebugInfoPatchPass.h
│ ├── ExportFixPass.h
│ ├── FunctionPass.h
│ ├── LandingPadFixPass.h
│ ├── MemAllocFixPass.h
│ ├── ModulePass.h
│ └── Win32ExceptionPass.h
│ ├── Passes.h
│ ├── TypeScriptCompiler
│ └── Defines.h
│ ├── TypeScriptDialect.h
│ ├── TypeScriptDialect.td
│ ├── TypeScriptDialectTranslation.h
│ ├── TypeScriptFunctionPass.h
│ ├── TypeScriptGC.h
│ ├── TypeScriptInterfaces.td
│ ├── TypeScriptLang
│ ├── TextDiagnostic.h
│ └── TextDiagnosticPrinter.h
│ ├── TypeScriptOps.h
│ ├── TypeScriptOps.td
│ ├── TypeScriptPassContext.h
│ ├── TypeScriptTypes.td
│ ├── VSCodeTemplate
│ └── Files.h
│ ├── Version.h
│ ├── VisitorAST.h
│ └── gcwrapper.h
├── lib
├── .vscode
│ ├── c_cpp_properties.json
│ └── settings.json
├── CMakeLists.txt
├── TypeScript
│ ├── AsyncDialectTranslation.cpp
│ ├── CMakeLists.txt
│ ├── DeclarationPrinter.cpp
│ ├── DiagnosticHelper.cpp
│ ├── GCPass.cpp
│ ├── LowerToAffineLoops.cpp
│ ├── LowerToLLVM.cpp
│ ├── MLIRGen.cpp
│ ├── ObjDumper.cpp
│ ├── RelocateConstantPass.cpp
│ ├── TypeScriptDialect.cpp
│ ├── TypeScriptDialectTranslation.cpp
│ └── TypeScriptOps.cpp
├── TypeScriptAliasPass
│ ├── AliasPass.cpp
│ └── CMakeLists.txt
├── TypeScriptAsyncRuntime
│ ├── AsyncRuntime.cpp
│ └── CMakeLists.txt
├── TypeScriptDebugInfoPass
│ ├── CMakeLists.txt
│ └── DebugInfoPatchPass.cpp
├── TypeScriptExceptionPass
│ ├── CMakeLists.txt
│ ├── LandingPadFixPass.cpp
│ └── Win32ExceptionPass.cpp
├── TypeScriptExportPass
│ ├── CMakeLists.txt
│ └── ExportFixPass.cpp
├── TypeScriptGC
│ ├── CMakeLists.txt
│ ├── TypeScriptGC.cpp
│ └── TypeScriptGCPrinter.cpp
├── TypeScriptMemAllocPass
│ ├── CMakeLists.txt
│ └── MemAllocFixPass.cpp
└── TypeScriptRuntime
│ ├── AsyncRuntime.cpp
│ ├── CMakeLists.txt
│ ├── DynamicRuntime.cpp
│ ├── MemRuntime.cpp
│ ├── TypeScriptGC.cpp
│ ├── gc.cpp
│ └── mlir_init.cpp
├── test
├── .vscode
│ ├── c_cpp_properties.json
│ ├── launch.json
│ └── settings.json
├── CMakeLists.txt
├── print-tester
│ ├── CMakeLists.txt
│ └── printer-tester.cpp
└── tester
│ ├── CMakeLists.txt
│ ├── helper.h
│ ├── test-runner.cpp
│ └── tests
│ ├── 00any.ts
│ ├── 00any_compare.ts
│ ├── 00any_generic_equals.ts
│ ├── 00any_types.ts
│ ├── 00array.ts
│ ├── 00array2.ts
│ ├── 00array3.ts
│ ├── 00array4_push_pop.ts
│ ├── 00array5_deconst.ts
│ ├── 00array6.ts
│ ├── 00array7.ts
│ ├── 00array8_tuple_spread.ts
│ ├── 00array_assignment5.ts
│ ├── 00array_cond_access.ts
│ ├── 00array_of.ts
│ ├── 00array_view.ts
│ ├── 00arrow_generic.ts
│ ├── 00arrow_global.ts
│ ├── 00arrow_in_arrow.ts
│ ├── 00as.ts
│ ├── 00as_const.ts
│ ├── 00assert.ts
│ ├── 00async_await.ts
│ ├── 00break_continue.ts
│ ├── 00class.ts
│ ├── 00class_abstract.ts
│ ├── 00class_access_control.ts
│ ├── 00class_accessor.ts
│ ├── 00class_accessor2.ts
│ ├── 00class_constr_fields.ts
│ ├── 00class_deconst.ts
│ ├── 00class_def_constr.ts
│ ├── 00class_discover_types.ts
│ ├── 00class_expression.ts
│ ├── 00class_expression2.ts
│ ├── 00class_expression3.ts
│ ├── 00class_from_tuple.ts
│ ├── 00class_generic.ts
│ ├── 00class_generic_iface.ts
│ ├── 00class_generic_method.ts
│ ├── 00class_generic_method2.ts
│ ├── 00class_iface.ts
│ ├── 00class_indexer.ts
│ ├── 00class_iterator.ts
│ ├── 00class_iterator_super.ts
│ ├── 00class_local_decl.ts
│ ├── 00class_nested.ts
│ ├── 00class_new.ts
│ ├── 00class_or_interface_to_tuple.ts
│ ├── 00class_protected_constr.ts
│ ├── 00class_recursive.ts
│ ├── 00class_stack.ts
│ ├── 00class_static.ts
│ ├── 00class_static_block.ts
│ ├── 00class_static_constr.ts
│ ├── 00class_static_generic_method.ts
│ ├── 00class_static_generic_method2.ts
│ ├── 00class_static_generic_method3.ts
│ ├── 00class_super.ts
│ ├── 00class_super_static.ts
│ ├── 00class_symbol_iterator.ts
│ ├── 00class_var_args.ts
│ ├── 00class_virtual_call.ts
│ ├── 00class_virtual_table.ts
│ ├── 00computedpropertyname.ts
│ ├── 00cond_expr.ts
│ ├── 00conditional_type.ts
│ ├── 00decorators.ts
│ ├── 00disposable.ts
│ ├── 00dowhile.ts
│ ├── 00enum.ts
│ ├── 00enum_multiple.ts
│ ├── 00equals.ts
│ ├── 00every.ts
│ ├── 00extends.ts
│ ├── 00extension.ts
│ ├── 00extension_cond_access.ts
│ ├── 00filter.ts
│ ├── 00for.ts
│ ├── 00for_await.ts
│ ├── 00for_await_yield.ts
│ ├── 00for_in.ts
│ ├── 00for_of.ts
│ ├── 00funcs.ts
│ ├── 00funcs_bindings.ts
│ ├── 00funcs_capture.ts
│ ├── 00funcs_expression_generic.ts
│ ├── 00funcs_expression_iterator.ts
│ ├── 00funcs_generic.ts
│ ├── 00funcs_generic_arrow.ts
│ ├── 00funcs_generic_iterator.ts
│ ├── 00funcs_generic_with_typeof.ts
│ ├── 00funcs_nesting.ts
│ ├── 00funcs_nesting_capture.ts
│ ├── 00funcs_nesting_generic.ts
│ ├── 00funcs_typed_generic_iterator.ts
│ ├── 00funcs_typeless_function_as_generic.ts
│ ├── 00funcs_vararg.ts
│ ├── 00generator.ts
│ ├── 00generator2.ts
│ ├── 00generator3.ts
│ ├── 00generator4.ts
│ ├── 00generator5.ts
│ ├── 00generator6.ts
│ ├── 00generic_arguments_name_conflict.ts
│ ├── 00globals.ts
│ ├── 00globals2.ts
│ ├── 00globals3.ts
│ ├── 00if_conditional_compile.ts
│ ├── 00if_return.ts
│ ├── 00in.ts
│ ├── 00infer.ts
│ ├── 00instanceof.ts
│ ├── 00interface.ts
│ ├── 00interface2.ts
│ ├── 00interface_conjunction.ts
│ ├── 00interface_generic.ts
│ ├── 00interface_indexer.ts
│ ├── 00interface_new.ts
│ ├── 00interface_object.ts
│ ├── 00interface_object2.ts
│ ├── 00interface_object3.ts
│ ├── 00interface_object4.ts
│ ├── 00interface_object5.ts
│ ├── 00interface_optional.ts
│ ├── 00interface_partial.ts
│ ├── 00intersection_type.ts
│ ├── 00intersection_type_generic.ts
│ ├── 00iterator.ts
│ ├── 00iterator_bug.ts
│ ├── 00lambdas.ts
│ ├── 00lambdas_generic_global.ts
│ ├── 00length.ts
│ ├── 00map.ts
│ ├── 00method_access_cond.ts
│ ├── 00names_conflict.ts
│ ├── 00new_delete.ts
│ ├── 00ns.ts
│ ├── 00ns2.ts
│ ├── 00ns3.ts
│ ├── 00ns4.ts
│ ├── 00ns5.ts
│ ├── 00ns_bug.ts
│ ├── 00numbers.ts
│ ├── 00object.ts
│ ├── 00object_accessor.ts
│ ├── 00object_deconst.ts
│ ├── 00object_func.ts
│ ├── 00object_func2.ts
│ ├── 00object_func3.ts
│ ├── 00object_global.ts
│ ├── 00object_new.ts
│ ├── 00optional.ts
│ ├── 00prefix_postfix.ts
│ ├── 00print.ts
│ ├── 00property_access_cond.ts
│ ├── 00question_question.ts
│ ├── 00reduce.ts
│ ├── 00reference_index_bug.ts
│ ├── 00reference_null_bug.ts
│ ├── 00safe_cast.ts
│ ├── 00safe_cast2.ts
│ ├── 00safe_cast_bug.ts
│ ├── 00safe_cast_field_access.ts
│ ├── 00safe_cast_typeof.ts
│ ├── 00safe_cast_while.ts
│ ├── 00sizeof.ts
│ ├── 00spread.ts
│ ├── 00spread_assignment.ts
│ ├── 00stack_test.ts
│ ├── 00str_null.ts
│ ├── 00strings.ts
│ ├── 00switch.ts
│ ├── 00switch_state.ts
│ ├── 00symbol.ts
│ ├── 00to_primitive_ops.ts
│ ├── 00try_catch.ts
│ ├── 00try_catch_rethrow.ts
│ ├── 00try_catch_return.ts
│ ├── 00try_catch_return_dispose.ts
│ ├── 00try_finally.ts
│ ├── 00try_finally_return.ts
│ ├── 00tuple.ts
│ ├── 00tuple_named.ts
│ ├── 00tuple_with_array.ts
│ ├── 00type_aliases_in_generics.ts
│ ├── 00type_guard_function.ts
│ ├── 00typed_array.ts
│ ├── 00types.ts
│ ├── 00types_indexedaccesstype.ts
│ ├── 00types_keyof_enum.ts
│ ├── 00types_mappedtype.ts
│ ├── 00types_templateliteraltype.ts
│ ├── 00types_unknown1.ts
│ ├── 00types_utility.ts
│ ├── 00uint_compare_bug.ts
│ ├── 00undef.ts
│ ├── 00union_bin_ops.ts
│ ├── 00union_bin_ops2.ts
│ ├── 00union_errors.ts
│ ├── 00union_ops.ts
│ ├── 00union_to_any.ts
│ ├── 00union_type.ts
│ ├── 00var_bindings.ts
│ ├── 00vars.ts
│ ├── 00void.ts
│ ├── 00while.ts
│ ├── 01any.ts
│ ├── 01arguments.ts
│ ├── 01class_new.ts
│ ├── 01disposable.ts
│ ├── 01enum.ts
│ ├── 01extends.ts
│ ├── 01extension.ts
│ ├── 01funcs_generic.ts
│ ├── 01funcs_generic_iterator.ts
│ ├── 01funcs_vararg.ts
│ ├── 01iterator.ts
│ ├── 01lambdas.ts
│ ├── 01map.ts
│ ├── 01method_access_cond.ts
│ ├── 01optional.ts
│ ├── 01print-bug.ts
│ ├── 01reduce.ts
│ ├── 01safe_cast_while.ts
│ ├── 01sizeof.ts
│ ├── 01spread.ts
│ ├── 01spread_assignment.ts
│ ├── 01switch.ts
│ ├── 01symbol.ts
│ ├── 01try_catch.ts
│ ├── 01try_catch_return_dispose.ts
│ ├── 01try_finally.ts
│ ├── 01tuple.ts
│ ├── 01types_mappedtype.ts
│ ├── 01types_templateliteraltype.ts
│ ├── 01types_utility.ts
│ ├── 01union_type.ts
│ ├── 02disposable.ts
│ ├── 02extends.ts
│ ├── 02funcs_generic_iterator.ts
│ ├── 02funcs_vararg.ts
│ ├── 02iterator.ts
│ ├── 02numbers.ts
│ ├── 02sizeof.ts
│ ├── 02union_type.ts
│ ├── 03iterator.ts
│ ├── 03union_type.ts
│ ├── 04union_type.ts
│ ├── 05strings.ts
│ ├── 05union_type.ts
│ ├── 06numbercollections.ts
│ ├── 07stringcollections.ts
│ ├── 08stringopertations.ts
│ ├── 09postprefix.ts
│ ├── 10arrayincrement.ts
│ ├── 11equalsoperator.ts
│ ├── 12referencecollection.ts
│ ├── 13actions.ts
│ ├── 14lazyoperations.ts
│ ├── 15references.ts
│ ├── 15references_capture.ts
│ ├── 17classes.ts
│ ├── 18enums.ts
│ ├── 19forof.ts
│ ├── 19forof_capture.ts
│ ├── 20maps.ts
│ ├── 22lambdas.ts
│ ├── 23generics.ts
│ ├── 241arrayforeach.ts
│ ├── 243arrayevery.ts
│ ├── 244arraysome.ts
│ ├── 25lamdacapture.ts
│ ├── 26staticclasses.ts
│ ├── 28boolcasts.ts
│ ├── 29lazyreferences.ts
│ ├── 32complexcalls.ts
│ ├── 33inheritance.ts
│ ├── 34switch.ts
│ ├── 35lambdaparameters.ts
│ ├── 36interfaces.ts
│ ├── 39objectdestructuring.ts
│ ├── 40generics.ts
│ ├── 41anonymoustypes.ts
│ ├── 42lambdaproperties.ts
│ ├── 43nestednamespace.ts
│ ├── 44toplevelcode.ts
│ ├── 45enumtostring.ts
│ ├── 48instanceof.ts
│ ├── 51exceptions.ts
│ ├── Grammar_and_types.ts
│ ├── abstractPropertyInConstructor.ts
│ ├── additionOperatorWithNumberAndEnum.ts
│ ├── arithmeticOperatorWithEnum.ts
│ ├── arithmeticOperatorWithTypeParameter.ts
│ ├── arrayFakeFlatNoCrashInferenceDeclarations.ts
│ ├── arrayLiterals.ts
│ ├── arrayLiterals2ES5.ts
│ ├── arrayLiterals3.ts
│ ├── assignmentTypeNarrowing.ts
│ ├── asyncMethodWithSuper_es2017.ts
│ ├── callWithSpread.ts
│ ├── comparisonOperatorWithIdenticalObjects.ts
│ ├── component.ts
│ ├── conditionalTypes1.ts
│ ├── conditionalTypes2.ts
│ ├── decl_class.ts
│ ├── decl_enum.ts
│ ├── decl_interface.ts
│ ├── decl_type.ts
│ ├── declarationsAndAssignments.ts
│ ├── declare_global_var.ts
│ ├── define_global_var.ts
│ ├── dependencies.ts
│ ├── disallowLineTerminatorBeforeArrow.ts
│ ├── emitDefaultParametersFunctionExpression.ts
│ ├── emit_class.ts
│ ├── emit_compiletime_class.ts
│ ├── emit_compiletime_func.ts
│ ├── emit_enum.ts
│ ├── emit_interface.ts
│ ├── emit_type.ts
│ ├── export_class_interface.ts
│ ├── export_enum.ts
│ ├── export_object_literal_with_class_types.ts
│ ├── export_object_literal_with_interface.ts
│ ├── export_vars.ts
│ ├── export_vars2.ts
│ ├── import_class_interface.ts
│ ├── import_enum.ts
│ ├── import_object_literal_with_class_types.ts
│ ├── import_object_literal_with_interface.ts
│ ├── import_vars.ts
│ ├── import_vars2.ts
│ ├── include_global_var.ts
│ ├── internals.ts
│ ├── load_store_decorators.ts
│ ├── logicalAssignment5.ts
│ ├── logicalAssignment5_2.ts
│ ├── logicalAssignment5_3.ts
│ ├── nbody.ts
│ ├── newWithSpread.ts
│ ├── noPropertyAccessFromIndexSignature1.ts
│ ├── no_main.ts
│ ├── parser.ts
│ ├── path.ts
│ ├── raytrace-0.ts
│ ├── raytrace.ts
│ ├── service.ts
│ ├── shared.ts
│ ├── structural-typing.ts
│ ├── thisTypeInClasses.ts
│ ├── typeGuardFunction.ts
│ ├── typeGuardOfFormThisMember.ts
│ ├── typeGuardOfFormTypeOfBoolean.ts
│ ├── types_vs_interfaces.ts
│ └── use_shared.ts
├── tsc-new-parser
├── .vscode
│ ├── c_cpp_properties.json
│ ├── launch.json
│ └── settings.json
├── CMakeLists.txt
├── config.h
├── core.h
├── debug.h
├── diagnostics.h
├── dump.h
├── enums.h
├── file_helper.h
├── incremental_parser.cpp
├── incremental_parser.h
├── node_factory.cpp
├── node_factory.h
├── node_test.h
├── parenthesizer_rules.cpp
├── parenthesizer_rules.h
├── parser.cpp
├── parser.h
├── parser_fwd_types.h
├── parser_jdoc.cpp
├── parser_jdoc.h
├── parser_run.cpp
├── parser_types.h
├── scanner.cpp
├── scanner.h
├── scanner_enums.h
├── scanner_run.cpp
├── types.h
├── undefined.h
└── utilities.h
├── tsc.natvis
├── tsc
├── .vscode
│ ├── c_cpp_properties.json
│ ├── launch.json
│ ├── settings.json
│ └── tasks.json
├── CMakeLists.txt
├── TextDiagnostic.cpp
├── TextDiagnosticPrinter.cpp
├── compile.cpp
├── declarationInline.cpp
├── defaultlib.cpp
├── dump.cpp
├── exe.cpp
├── jit.cpp
├── obj.cpp
├── opts.cpp
├── transform.cpp
├── tsc.cpp
├── utils.cpp
└── vscode.cpp
└── unittests
├── .vscode
└── settings.json
├── CMakeLists.txt
├── Example
├── CMakeLists.txt
└── Example.cpp
└── MLIRGen
├── CMakeLists.txt
└── TypeToString.cpp
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Set the default behavior, in case people don't have core.autocrlf set.
2 | * text=auto
3 |
4 | # Explicitly declare text files you want to always be normalized and converted
5 | # to native line endings on checkout.
6 | *.c text
7 | *.h text
8 | *.cpp text
9 | *.hxx text
10 | *.cxx text
11 | *.txt text
12 | *.sh text
13 | *.cmake text
14 | *.guess text
15 | *.md text
16 |
17 | # Declare files that will always have CRLF line endings on checkout.
18 | *.sln text eol=crlf
19 |
20 | # Denote all files that are truly binary and should not be modified.
21 | *.png binary
22 | *.jpg binary
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | github: [ASDAlexander77]
2 | custom: ['https://www.paypal.com/donate/?hosted_button_id=BBJ4SQYLA6D2L']
3 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/custom.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Custom issue template
3 | about: Describe this issue template's purpose here.
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.github/codeql/codeql-config.yml:
--------------------------------------------------------------------------------
1 | name: "CodeQL config"
2 |
3 | queries:
4 | # - name: Run custom queries
5 | # uses: ./queries
6 | - uses: security-extended
7 | - uses: security-and-quality
8 |
9 | disable-default-queries: false
10 |
11 | #no uaws in cpp
12 | #paths:
13 | # - tsc
14 |
15 | #no uaws in cpp
16 | #paths-ignore:
17 | # - __build
18 | # - 3rdParty
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | __build
2 | build
3 | 3rdParty/*
4 | !3rdParty/llvm-project
5 | .vs
6 | .antlr
7 | tsc/out
8 | tsc/Testing
9 | tsc/Testing/Temporary/*
10 | tsc/test/tester/tests/*.d.ts
11 | package-lock.json
12 | node_modules
13 | gc-*
14 | libatomic_ops-*
15 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "3rdParty/llvm-project"]
2 | path = 3rdParty/llvm-project
3 | url = https://github.com/llvm/llvm-project.git
4 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | os: windows
2 | language: cpp
3 | git:
4 | submodules: false
5 | before_script:
6 | # - choco install python --pre
7 | - wget -O llvm_13_release.zip -q https://www.dropbox.com/s/o8hrv8ppqayu6vg/llvm_13_release.zip?dl=1
8 | - pwd
9 | - dir
10 | - mkdir -p __build/llvm/release
11 | - mkdir -p __build/tsc-release
12 | - mkdir -p 3rdParty/llvm/
13 | - unzip -q ./llvm_13_release.zip -d ./3rdParty/llvm/
14 | script:
15 | - cd __build/tsc-release
16 | - cmake ../../tsc -G "Visual Studio 15 2017" -A x64 -DCMAKE_BUILD_TYPE=Release -Wno-dev
17 | - cmake --build . --config Release -j 8
18 |
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools"
3 | }
--------------------------------------------------------------------------------
/3rdParty_cleanup.bat:
--------------------------------------------------------------------------------
1 | rd /S /Q __build\gc
2 | rd /S /Q __build\llvm
3 | rd /S /Q 3rdParty\gc
4 | rd /S /Q 3rdParty\llvm
--------------------------------------------------------------------------------
/cleanup.bat:
--------------------------------------------------------------------------------
1 | git submodule foreach --recursive git gc
--------------------------------------------------------------------------------
/docs/VisualStudio/CustomTool/tsc.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Midl
5 | CustomBuild
6 |
7 |
8 |
9 | $(IntDir)%(FileName).obj
10 | "tsc.exe" --emit=obj -o=$(IntDir)%(FileName).obj [AllOptions] [AdditionalOptions] "%(FullPath)"
11 | Compiling %(Filename)%(Extension)
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/docs/bugs/bug14.ts:
--------------------------------------------------------------------------------
1 | type typeAlias1 = typeof varOfAliasedType1;
2 | var varOfAliasedType1: typeAlias1;
3 |
4 | var varOfAliasedType2: typeAlias2;
5 | type typeAlias2 = typeof varOfAliasedType2;
6 |
7 | function func(): typeAlias3 { return null; }
8 | var varOfAliasedType3 = func();
9 | type typeAlias3 = typeof varOfAliasedType3;
10 |
11 | // Repro from #26104
12 |
13 | interface Input {
14 | a: number;
15 | b: number;
16 | }
17 |
18 | type R = ReturnType;
19 | function mul(input: Input): R {
20 | return input.a * input.b;
21 | }
22 |
23 | // Repro from #26104
24 |
25 | type R2 = ReturnType;
26 | function f(): R2 { return 0; }
27 |
28 | function main() {
29 | print("done.");
30 | }
31 |
--------------------------------------------------------------------------------
/docs/bugs/bug21.ts:
--------------------------------------------------------------------------------
1 | class C3 {
2 | //g: new (x: this) => this;
3 | g: new (x: this) => x;
4 | }
5 |
6 | function main() {
7 |
8 | const c3 = new C3();
9 | const r = c3.g(c3);
10 |
11 | assert(c3 == r);
12 |
13 | print("done.");
14 | }
15 |
--------------------------------------------------------------------------------
/docs/bugs/generic_in_generic.ts:
--------------------------------------------------------------------------------
1 | function render(screenWidth, screenHeight) {
2 | const getPoint = (x, y) => {
3 | const recenterX = x => (x - (screenWidth / 2.0)) / 2.0 / screenWidth;
4 | const recenterY = y => -(y - (screenHeight / 2.0)) / 2.0 / screenHeight;
5 | return recenterX(x) + recenterY(y);
6 | }
7 |
8 | const v = getPoint(512, 384);
9 | print(v);
10 | assert(v === 0);
11 |
12 | const v2 = getPoint(1024, 768);
13 | print(v2);
14 | assert(v2 === 0);
15 |
16 | const v3 = getPoint(300, 200);
17 | print(v3);
18 | assert((v3 - 0.016276) < 0.0001);
19 |
20 | }
21 |
22 | render(1024, 768);
23 |
24 | print('done');
--------------------------------------------------------------------------------
/docs/compiler-explorer/etc/config/typescript.defaults.properties:
--------------------------------------------------------------------------------
1 | # Default settings for TypeScript Compiler
2 | compilers=&tsc
3 | compilerType=typescript
4 | versionFlag=--version
5 |
6 | group.tsc.compilers=tsc_jit_gc:tsc_jit_nogc
7 | compiler.tsc_jit_gc.exe=/home/alex/TypeScriptCompiler/__build/tsc-ninja/bin/tsc
8 | compiler.tsc_jit_gc.sharedlibs=/home/alex/TypeScriptCompiler/__build/tsc-ninja/lib/libTypeScriptRuntime.so
9 | compiler.tsc_jit_gc.name=TypeScript JIT (GC)
10 | compiler.tsc_jit_nogc.exe=/home/alex/TypeScriptCompiler/__build/tsc-ninja/bin/tsc
11 | compiler.tsc_jit_nogc.sharedlibs=
12 | compiler.tsc_jit_nogc.name=TypeScript JIT (No GC)
13 |
14 | defaultCompiler=tsc_jit_gc
15 | supportsBinary=false
16 | supportsExecute=true
17 | interpreted=true
18 |
19 |
--------------------------------------------------------------------------------
/docs/compiler-explorer/examples/typescript/default.ts:
--------------------------------------------------------------------------------
1 | function main()
2 | {
3 | print("Hello World!");
4 | }
--------------------------------------------------------------------------------
/docs/compiler-explorer/infra/bin/yaml/typescript.yaml:
--------------------------------------------------------------------------------
1 | compilers:
2 | tsc-native:
3 | type: tarballs
4 | dir: tsc-{name}
5 | untar_dir: tsc-ninja-release
6 | compression: gz
7 | check_exe: bin/tsc --version
8 | url: https://github.com/ASDAlexander77/TypeScriptCompiler/releases/download/v{name}/tsc.tar.gz
9 | targets:
10 | - 0.0-pre-alpha20
11 |
12 |
--------------------------------------------------------------------------------
/docs/fixes.txt:
--------------------------------------------------------------------------------
1 | 1) can't copy compiled files
2 |
3 | Solution:
4 |
5 | https://stackoverflow.com/questions/46108390/building-llvm-with-cmake-and-visual-stuidio-fails-to-install
6 |
7 | https://github.com/llvm/llvm-project/blob/master/compiler-rt/cmake/Modules/AddCompilerRT.cmake#L12
8 |
9 | string(REGEX REPLACE "\\$\\(Configuration\\)" "$" output_dir "${output_dir}")
10 |
11 | 2) mlir_async_runtime.lib is missing
12 |
13 | Solution:
14 |
15 | in MLIRTargets-release.cmake comment lines
16 |
17 | list(APPEND _IMPORT_CHECK_FILES_FOR_mlir_async_runtime "${_IMPORT_PREFIX}/lib/mlir_async_runtime.lib" "${_IMPORT_PREFIX}/bin/mlir_async_runtime.dll" )
18 |
19 |
--------------------------------------------------------------------------------
/docs/how/cmake/gc_example/config_debug.bat:
--------------------------------------------------------------------------------
1 | pushd
2 | mkdir "__build/debug"
3 | cd "__build/debug"
4 | cmake ../.. -G "Visual Studio 17 2022" -A x64 -DCMAKE_BUILD_TYPE=Debug -Wno-dev
5 | cmake --build . --config Debug -j 1
6 | popd
7 |
--------------------------------------------------------------------------------
/docs/how/cmake/gc_example/config_llvm_debug.bat:
--------------------------------------------------------------------------------
1 | pushd
2 | mkdir "__build/debug-ninja"
3 | cd "__build/debug-ninja"
4 | cmake ../.. -G "Ninja" -DCMAKE_BUILD_TYPE=Debug -Wno-dev -DCMAKE_TOOLCHAIN_FILE=../../llvm_tool.cmake
5 | cmake --build . --config Debug -j 1
6 | popd
7 |
--------------------------------------------------------------------------------
/docs/how/cmake/gc_example/config_llvm_win_debug.bat:
--------------------------------------------------------------------------------
1 | pushd
2 | mkdir "__build/debug-ninja"
3 | cd "__build/debug-ninja"
4 | cmake ../.. -G "Ninja" -DCMAKE_BUILD_TYPE=Debug -Wno-dev -DCMAKE_TOOLCHAIN_FILE=../../llvm_tool_win.cmake
5 | cmake --build . --config Debug -j 1
6 | popd
7 |
--------------------------------------------------------------------------------
/docs/how/cmake/gc_example/config_release.bat:
--------------------------------------------------------------------------------
1 | pushd
2 | mkdir "__build/release"
3 | cd "__build/release"
4 | cmake ../.. -G "Visual Studio 16 2019" -A x64 -DCMAKE_BUILD_TYPE=Release -Wno-dev
5 | cmake --build . --config Release -j 1
6 | popd
7 |
--------------------------------------------------------------------------------
/docs/how/cmake/gc_example/dummy.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ASDAlexander77/TypeScriptCompiler/e3ae5fa6310ae97bdcdfbafc327119fdada569a9/docs/how/cmake/gc_example/dummy.cpp
--------------------------------------------------------------------------------
/docs/how/cmake/gc_example/llvm_tool.cmake:
--------------------------------------------------------------------------------
1 | # llvm toolchain
2 | set(CMAKE_C_COMPILER "clang")
3 | set(CMAKE_CPP_COMPILER "clang++")
4 | set(CMAKE_AR "llvm-ar")
5 | set(CMAKE_LINKER "lld")
6 |
--------------------------------------------------------------------------------
/docs/how/cmake/gc_example/llvm_tool_win.cmake:
--------------------------------------------------------------------------------
1 | # llvm toolchain
2 | set(CMAKE_C_COMPILER "clang-cl.exe")
3 | set(CMAKE_CPP_COMPILER "clang++.exe")
4 | set(CMAKE_AR "llvm-ar.exe")
5 | set(CMAKE_LINKER "lld-link.exe")
6 |
--------------------------------------------------------------------------------
/docs/how/cmake/gc_example/src/main.ts:
--------------------------------------------------------------------------------
1 | function main()
2 | {
3 | print("Hello World");
4 | }
--------------------------------------------------------------------------------
/docs/how/cmake_vulkan/config_debug.bat:
--------------------------------------------------------------------------------
1 | pushd
2 | mkdir "__build/debug"
3 | cd "__build/debug"
4 | cmake ../.. -G "Visual Studio 16 2019" -A x64 -DCMAKE_BUILD_TYPE=Debug -Wno-dev
5 | cmake --build . --config Debug -j 1
6 | popd
7 |
--------------------------------------------------------------------------------
/docs/how/cmake_vulkan/config_llvm_debug.bat:
--------------------------------------------------------------------------------
1 | pushd
2 | mkdir "__build/debug-ninja"
3 | cd "__build/debug-ninja"
4 | cmake ../.. -G "Ninja" -DCMAKE_BUILD_TYPE=Debug -Wno-dev -DCMAKE_TOOLCHAIN_FILE=../../llvm_tool.cmake
5 | cmake --build . --config Debug -j 1
6 | popd
7 |
--------------------------------------------------------------------------------
/docs/how/cmake_vulkan/config_llvm_win_debug.bat:
--------------------------------------------------------------------------------
1 | pushd
2 | mkdir "__build/debug-ninja"
3 | cd "__build/debug-ninja"
4 | cmake ../.. -G "Ninja" -DCMAKE_BUILD_TYPE=Debug -Wno-dev -DCMAKE_TOOLCHAIN_FILE=../../llvm_tool_win.cmake
5 | cmake --build . --config Debug -j 1
6 | popd
7 |
--------------------------------------------------------------------------------
/docs/how/cmake_vulkan/config_release.bat:
--------------------------------------------------------------------------------
1 | pushd
2 | mkdir "__build/release"
3 | cd "__build/release"
4 | cmake ../.. -G "Visual Studio 16 2019" -A x64 -DCMAKE_BUILD_TYPE=Release -Wno-dev
5 | cmake --build . --config Release -j 1
6 | popd
7 |
--------------------------------------------------------------------------------
/docs/how/cmake_vulkan/dummy.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ASDAlexander77/TypeScriptCompiler/e3ae5fa6310ae97bdcdfbafc327119fdada569a9/docs/how/cmake_vulkan/dummy.cpp
--------------------------------------------------------------------------------
/docs/how/cmake_vulkan/llvm_tool.cmake:
--------------------------------------------------------------------------------
1 | # llvm toolchain
2 | set(CMAKE_C_COMPILER "clang")
3 | set(CMAKE_CPP_COMPILER "clang++")
4 | set(CMAKE_AR "llvm-ar")
5 | set(CMAKE_LINKER "lld")
6 |
--------------------------------------------------------------------------------
/docs/how/cmake_vulkan/llvm_tool_win.cmake:
--------------------------------------------------------------------------------
1 | # llvm toolchain
2 | set(CMAKE_C_COMPILER "clang-cl.exe")
3 | set(CMAKE_CPP_COMPILER "clang++.exe")
4 | set(CMAKE_AR "llvm-ar.exe")
5 | set(CMAKE_LINKER "lld-link.exe")
6 |
--------------------------------------------------------------------------------
/docs/how/cmake_vulkan/native/window.win32.h:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #include
4 | #include
5 | #include
--------------------------------------------------------------------------------
/docs/how/cmake_vulkan/src/application.ts:
--------------------------------------------------------------------------------
1 | import "./appwindow";
2 |
3 | export class Application {
4 | static appWindow: AppWindow;
5 |
6 | export static run() {
7 | this.appWindow = new AppWindow();
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/docs/how/cmake_vulkan/src/main.ts:
--------------------------------------------------------------------------------
1 | import "./application";
2 |
3 | export function Main()
4 | {
5 | Application.run();
6 | }
--------------------------------------------------------------------------------
/docs/how/cmake_winapp/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
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 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "name": "(Windows-LLDB) TypeScriptApp - Launch",
9 | "type": "lldb-vscode",
10 | "request": "launch",
11 | "program": "${workspaceRoot}/__build/TypeScriptApp.exe",
12 | "args": [],
13 | "env": [],
14 | "cwd": "${workspaceRoot}",
15 | "windows": {}
16 | }
17 | ]
18 | }
--------------------------------------------------------------------------------
/docs/how/cmake_winapp/config_debug.bat:
--------------------------------------------------------------------------------
1 | pushd
2 | mkdir "__build/debug"
3 | cd "__build/debug"
4 | cmake ../.. -G "Visual Studio 16 2019" -A x64 -DCMAKE_BUILD_TYPE=Debug -Wno-dev
5 | cmake --build . --config Debug -j 1
6 | popd
7 |
--------------------------------------------------------------------------------
/docs/how/cmake_winapp/config_llvm_debug.bat:
--------------------------------------------------------------------------------
1 | pushd
2 | mkdir "__build/debug-ninja"
3 | cd "__build/debug-ninja"
4 | cmake ../.. -G "Ninja" -DCMAKE_BUILD_TYPE=Debug -Wno-dev -DCMAKE_TOOLCHAIN_FILE=../../llvm_tool.cmake
5 | cmake --build . --config Debug -j 1
6 | popd
7 |
--------------------------------------------------------------------------------
/docs/how/cmake_winapp/config_llvm_win_debug.bat:
--------------------------------------------------------------------------------
1 | pushd
2 | mkdir "__build/debug-ninja"
3 | cd "__build/debug-ninja"
4 | cmake ../.. -G "Ninja" -DCMAKE_BUILD_TYPE=Debug -Wno-dev -DCMAKE_TOOLCHAIN_FILE=../../llvm_tool_win.cmake
5 | cmake --build . --config Debug -j 1
6 | popd
7 |
--------------------------------------------------------------------------------
/docs/how/cmake_winapp/config_release.bat:
--------------------------------------------------------------------------------
1 | pushd
2 | mkdir "__build/release"
3 | cd "__build/release"
4 | cmake ../.. -G "Visual Studio 16 2019" -A x64 -DCMAKE_BUILD_TYPE=Release -Wno-dev
5 | cmake --build . --config Release -j 1
6 | popd
7 |
--------------------------------------------------------------------------------
/docs/how/cmake_winapp/dummy.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ASDAlexander77/TypeScriptCompiler/e3ae5fa6310ae97bdcdfbafc327119fdada569a9/docs/how/cmake_winapp/dummy.cpp
--------------------------------------------------------------------------------
/docs/how/cmake_winapp/llvm_tool.cmake:
--------------------------------------------------------------------------------
1 | # llvm toolchain
2 | set(CMAKE_C_COMPILER "clang")
3 | set(CMAKE_CPP_COMPILER "clang++")
4 | set(CMAKE_AR "llvm-ar")
5 | set(CMAKE_LINKER "lld")
6 |
--------------------------------------------------------------------------------
/docs/how/cmake_winapp/llvm_tool_win.cmake:
--------------------------------------------------------------------------------
1 | # llvm toolchain
2 | set(CMAKE_C_COMPILER "clang-cl.exe")
3 | set(CMAKE_CPP_COMPILER "clang++.exe")
4 | set(CMAKE_AR "llvm-ar.exe")
5 | set(CMAKE_LINKER "lld-link.exe")
6 |
--------------------------------------------------------------------------------
/docs/how/cmake_winapp/native/window.win32.h:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #include
4 | #include
5 | #include
--------------------------------------------------------------------------------
/docs/how/cmake_winapp/src/application.ts:
--------------------------------------------------------------------------------
1 | import "./appwindow";
2 |
3 | export class Application {
4 | static appWindow: AppWindow;
5 |
6 | export static run() {
7 | this.appWindow = new AppWindow();
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/docs/how/cmake_winapp/src/main.ts:
--------------------------------------------------------------------------------
1 | import "./application";
2 |
3 | export function Main()
4 | {
5 | Application.run();
6 | }
--------------------------------------------------------------------------------
/docs/how/wasm/test/1.bat:
--------------------------------------------------------------------------------
1 | cd wasm
2 | pwsh ../test_wasm.ps1
--------------------------------------------------------------------------------
/docs/how/wasm/wasm/hello.wasm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ASDAlexander77/TypeScriptCompiler/e3ae5fa6310ae97bdcdfbafc327119fdada569a9/docs/how/wasm/wasm/hello.wasm
--------------------------------------------------------------------------------
/docs/how/wasm/wasm/tsc_wasm.bat:
--------------------------------------------------------------------------------
1 | set GC_LIB_PATH=C:\dev\TypeScriptCompiler\__build\gc\msbuild\x64\debug\Debug
2 | set LLVM_LIB_PATH=C:\dev\TypeScriptCompiler\__build\llvm\msbuild\x64\debug\Debug\lib
3 | set TSC_LIB_PATH=C:\dev\TypeScriptCompiler\__build\tsc\windows-msbuild-debug\lib
4 | C:\dev\TypeScriptCompiler\__build\tsc\windows-msbuild-debug\bin\tsc.exe --emit=exe --nogc --di -mtriple=wasm32-unknown-unknown C:\temp\1.ts
5 | copy 1.wasm C:\temp\webassembly3\hello.wasm
--------------------------------------------------------------------------------
/docs/how/wasm/wasm/tsc_wasm_emscripten.bat:
--------------------------------------------------------------------------------
1 | set GC_LIB_PATH=C:\dev\TypeScriptCompiler\__build\gc\msbuild\x64\debug\Debug
2 | set LLVM_LIB_PATH=C:\dev\TypeScriptCompiler\__build\llvm\msbuild\x64\debug\Debug\lib
3 | set TSC_LIB_PATH=C:\dev\TypeScriptCompiler\__build\tsc\windows-msbuild-debug\lib
4 | set EMSDK_SYSROOT_PATH=C:\utils\emsdk\upstream\emscripten\cache\sysroot
5 | C:\dev\TypeScriptCompiler\__build\tsc\windows-msbuild-debug\bin\tsc.exe --emit=exe --nogc -mtriple=wasm32-pc-emscripten C:\temp\1.ts
6 | copy 1.wasm C:\temp\webassembly3\hello.wasm
--------------------------------------------------------------------------------
/docs/not_impl/not_impl12.ts:
--------------------------------------------------------------------------------
1 | function testLoopScope() {
2 | for (let i = 0; i < 3; ++i) {
3 | let val: number;
4 | // TODO:
5 | assert(val === undefined, "loopscope");
6 | val = i;
7 | }
8 | }
9 |
10 | function main() {
11 | testLoopScope();
12 | print("done.");
13 | }
--------------------------------------------------------------------------------
/docs/not_impl/not_impl13.ts:
--------------------------------------------------------------------------------
1 | class ConcreteA {}
2 | class ConcreteB {}
3 |
4 | function main()
5 | {
6 | [ConcreteA, ConcreteB].map(cls => new cls()); // should work
7 | print("done.");
8 | }
--------------------------------------------------------------------------------
/docs/not_impl/not_impl15.ts:
--------------------------------------------------------------------------------
1 | //@target: ES5
2 | interface A {
3 | prop: string;
4 | raw: string;
5 | m(): void;
6 | }
7 | abstract class B implements A {
8 | abstract prop: string;
9 | abstract raw: string;
10 | abstract readonly ro: string;
11 | abstract get readonlyProp(): string;
12 | abstract set readonlyProp(val: string);
13 | abstract m(): void;
14 | }
15 | class C extends B {
16 | get prop() { return "foo"; }
17 | set prop(v) { }
18 | raw = "edge";
19 | readonly ro = "readonly please";
20 | readonlyProp: string; // don't have to give a value, in fact
21 | m() { }
22 | }
--------------------------------------------------------------------------------
/docs/not_impl/not_impl19.ts:
--------------------------------------------------------------------------------
1 | interface ClockConstructor {
2 | new(hour: number, minute: number): ClockInterface;
3 | }
4 |
5 | interface ClockInterface {
6 | tick(): void;
7 | }
8 |
9 | function main() {
10 | const ClockInst: ClockConstructor = class Clock implements ClockInterface {
11 | constructor(h: number, m: number) { }
12 | tick() {
13 | print("beep beep");
14 | }
15 | };
16 |
17 | let clock = new ClockInst(12, 17);
18 | clock.tick();
19 | }
--------------------------------------------------------------------------------
/docs/not_impl/not_impl20.ts:
--------------------------------------------------------------------------------
1 | function drawText({ text = "", location: [x, y] = [0, 0], bold = false }) {
2 | print(text, x, y, bold);
3 | assert(text == "someText");
4 | assert(x == 1);
5 | assert(y == 2);
6 | assert(bold);
7 | }
8 |
9 | function main() {
10 |
11 | //const item = { text: "someText", location: [1, 2, 3], style: "italics" };
12 | //drawText(item);
13 | const item2 = { text: "someText", location: [1, 2, 3], bold: true };
14 | drawText(item2);
15 |
16 | print("done.");
17 | }
--------------------------------------------------------------------------------
/docs/not_impl/not_impl26.ts:
--------------------------------------------------------------------------------
1 | class B {
2 | constructor(x: number, y: number, ...z: string[]) { print("constr", x, y); }
3 | }
4 |
5 | function main() {
6 |
7 | let dd : {
8 | new(x: number, y: number, ...z: string[]);
9 | } = B;
10 |
11 | const ss = new dd(1, 2);
12 |
13 | print("done");
14 | }
--------------------------------------------------------------------------------
/docs/not_impl/not_impl31.ts:
--------------------------------------------------------------------------------
1 | export class Point {
2 | x: number;
3 | y: number;
4 | }
5 |
6 | export var Origin: Point = { x: 0, y: 0 };
7 |
8 | function main() {
9 | print("done.");
10 | }
--------------------------------------------------------------------------------
/docs/not_impl/not_impl5.ts:
--------------------------------------------------------------------------------
1 | function getPointFactory(x: number, y: number) {
2 | class P {
3 | x = x;
4 | y = y;
5 | }
6 |
7 | return P;
8 | }
9 |
10 | function main() {
11 | const PointZero = getPointFactory(0, 0);
12 | const PointOne = getPointFactory(1, 1);
13 | }
--------------------------------------------------------------------------------
/docs/not_impl/not_impl9.ts:
--------------------------------------------------------------------------------
1 | interface Observable {
2 | map(proj: (el: T) => U): Observable;
3 | }
4 |
5 | function main() {
6 | let o: Observable;
7 | o.map();
8 | }
--------------------------------------------------------------------------------
/docs/todo.txt:
--------------------------------------------------------------------------------
1 | 1) Add types ThisType and ParamType to be able to carry names with types for functions
2 |
3 | 3) SideEffectInterfaces.td - C:\dev\TypeScriptCompiler\3rdParty\llvm-project\mlir\include\mlir\Interfaces\SideEffectInterfaces.td
4 | set all Ops with correct side effect (memory read, write etc) needed for optimization
5 |
--------------------------------------------------------------------------------
/prepare_3rdParty_debug.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | echo "Downloading LLVM"
3 | git submodule update --init --recursive
4 | echo "Configuring LLVM (Debug)"
5 | ./scripts/config_llvm_debug.sh
6 | echo "Building LLVM (Debug)"
7 | ./scripts/build_llvm_debug.sh
8 | echo "Building GC (Debug)"
9 | curl -o gc-8.0.4.tar.gz https://www.hboehm.info/gc/gc_source/gc-8.0.4.tar.gz
10 | curl -o libatomic_ops-7.6.10.tar.gz https://www.hboehm.info/gc/gc_source/libatomic_ops-7.6.10.tar.gz
11 | tar -xvzf gc-8.0.4.tar.gz -C ./3rdParty/
12 | tar -xvzf libatomic_ops-7.6.10.tar.gz -C ./3rdParty/
13 | cp -a ./3rdParty/libatomic_ops-7.6.10/ ./3rdParty/gc-8.0.4/libatomic_ops/
14 | cp -ar ./docs/fix/gc/* ./3rdParty/gc-8.0.4/
15 | ./scripts/build_gc_debug.sh
16 |
17 |
18 |
--------------------------------------------------------------------------------
/prepare_3rdParty_lldb.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 | set BUILD=debug
3 | if not "%1"=="" (
4 | set BUILD=%1
5 | )
6 |
7 | set p=%cd%
8 |
9 | echo "Configuring LLDB (%BUILD%)"
10 | cd %p%
11 | @call scripts\config_lldb_%BUILD%.bat
12 | echo "Building LLDB (%BUILD%)"
13 | cd %p%
14 | @call scripts\build_lldb_%BUILD%.bat
15 |
--------------------------------------------------------------------------------
/prepare_3rdParty_release.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | echo "Downloading LLVM"
3 | git submodule update --init --recursive
4 | echo "Configuring LLVM (Release)"
5 | ./scripts/config_llvm_release.sh
6 | echo "Building LLVM (Release)"
7 | ./scripts/build_llvm_release.sh
8 | echo "Building GC (Release)"
9 | curl -o gc-8.0.4.tar.gz https://www.hboehm.info/gc/gc_source/gc-8.0.4.tar.gz
10 | curl -o libatomic_ops-7.6.10.tar.gz https://www.hboehm.info/gc/gc_source/libatomic_ops-7.6.10.tar.gz
11 | tar -xvzf gc-8.0.4.tar.gz -C ./3rdParty/
12 | tar -xvzf libatomic_ops-7.6.10.tar.gz -C ./3rdParty/
13 | cp -a ./3rdParty/libatomic_ops-7.6.10/ ./3rdParty/gc-8.0.4/libatomic_ops/
14 | cp -ar ./docs/fix/gc/* ./3rdParty/gc-8.0.4/
15 | ./scripts/build_gc_release.sh
16 |
17 |
18 |
--------------------------------------------------------------------------------
/prepare_3rdParty_wasm_debug.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | echo "Configuring LLVM (Debug) (WASM)"
3 | ./scripts/config_llvm_wasm_debug.sh
4 | echo "Building LLVM (Debug) (WASM)"
5 | ./scripts/build_llvm_wasm_debug.sh
6 |
--------------------------------------------------------------------------------
/scripts/build_gc_debug.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | mkdir -p __build/gc/ninja/debug
3 | mkdir -p 3rdParty/gc/debug
4 | cd __build/gc/ninja/debug
5 | cmake ../../../../3rdParty/gc-8.0.4 -G "Ninja" -DCMAKE_BUILD_TYPE=Debug -Wno-dev -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_INSTALL_PREFIX=../../../../3rdParty/gc/debug -Denable_threads=ON -Denable_cplusplus=OFF
6 | cmake --build . --config Debug -j 16
7 | cp ./lib* ../../../../3rdParty/gc/debug/
8 |
--------------------------------------------------------------------------------
/scripts/build_gc_debug_ninja.bat:
--------------------------------------------------------------------------------
1 | pushd
2 | mkdir __build\gc\ninja\debug
3 | cd __build\gc\ninja\debug
4 | cmake ../../../../3rdParty/gc-8.0.4 -G "Ninja" -DCMAKE_BUILD_TYPE=Debug -Wno-dev -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_INSTALL_PREFIX=../../../../3rdParty/gc/debug -Denable_threads=ON -Denable_cplusplus=OFF
5 | cmake --build . --config Debug -j 8
6 | popd
--------------------------------------------------------------------------------
/scripts/build_gc_debug_vs.bat:
--------------------------------------------------------------------------------
1 | pushd
2 | mkdir __build\gc\msbuild\x64\debug
3 | cd __build\gc\msbuild\x64\debug
4 | if exist "C:/Program Files/Microsoft Visual Studio/2022/Professional" set EXTRA_PARAM=-DCMAKE_GENERATOR_INSTANCE="C:/Program Files/Microsoft Visual Studio/2022/Professional"
5 | cmake ../../../../../3rdParty/gc-8.0.4 -G "Visual Studio 17 2022" -A x64 %EXTRA_PARAM% -DCMAKE_BUILD_TYPE=Debug -Wno-dev -DCMAKE_INSTALL_PREFIX=../../../../../3rdParty/gc/x64/debug -Denable_threads=ON -Denable_cplusplus=OFF
6 | cmake --build . --config Debug -j 8
7 | popd
--------------------------------------------------------------------------------
/scripts/build_gc_release.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | mkdir -p __build/gc/ninja/release
3 | mkdir -p 3rdParty/gc/release
4 | cd __build/gc/ninja/release
5 | cmake ../../../../3rdParty/gc-8.0.4 -G "Ninja" -DCMAKE_BUILD_TYPE=Release -Wno-dev -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_INSTALL_PREFIX=../../../../3rdParty/gc/release -Denable_threads=ON -Denable_cplusplus=OFF
6 | cmake --build . --config Release -j 16
7 | cp ./lib* ../../../../3rdParty/gc/release/
--------------------------------------------------------------------------------
/scripts/build_gc_release_ninja.bat:
--------------------------------------------------------------------------------
1 | pushd
2 | mkdir __build\gc\ninja\release
3 | cd __build\gc\ninja\release
4 | cmake ../../../../3rdParty/gc-8.0.4 -G "Ninja" -DCMAKE_BUILD_TYPE=Release -Wno-dev -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_INSTALL_PREFIX=../../../../3rdParty/gc/release -Denable_threads=ON -Denable_cplusplus=OFF
5 | cmake --build . --config Release -j 8
6 | cmake --install . --config Release
7 | popd
--------------------------------------------------------------------------------
/scripts/build_gc_release_vs.bat:
--------------------------------------------------------------------------------
1 | pushd
2 | mkdir __build\gc\msbuild\x64\release
3 | cd __build\gc\msbuild\x64\release
4 | if exist "C:/Program Files/Microsoft Visual Studio/2022/Professional" set EXTRA_PARAM=-DCMAKE_GENERATOR_INSTANCE="C:/Program Files/Microsoft Visual Studio/2022/Professional"
5 | cmake ../../../../../3rdParty/gc-8.0.4 -G "Visual Studio 17 2022" -A x64 %EXTRA_PARAM% -DCMAKE_BUILD_TYPE=Release -Wno-dev -DCMAKE_INSTALL_PREFIX=../../../../../3rdParty/gc/x64/release -Denable_threads=ON -Denable_cplusplus=OFF
6 | cmake --build . --config Release -j 8
7 | cmake --install . --config Release
8 | popd
--------------------------------------------------------------------------------
/scripts/build_lldb_debug.bat:
--------------------------------------------------------------------------------
1 | pushd
2 | cd __build\lldb\ninja\debug
3 | cmake --build . --config Debug --target install -j 8
4 | cmake --install . --config Debug
5 | popd
--------------------------------------------------------------------------------
/scripts/build_lldb_release.bat:
--------------------------------------------------------------------------------
1 | pushd
2 | cd __build\lldb\ninja\release
3 | cmake --build . --config Release --target install -j 8
4 | cmake --install . --config Release
5 | popd
--------------------------------------------------------------------------------
/scripts/build_llvm_debug.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | cd __build/llvm/ninja/debug
3 | cmake --build . --config Debug --target install -j 2
4 | cmake --install . --config Debug
5 |
--------------------------------------------------------------------------------
/scripts/build_llvm_debug_ninja.bat:
--------------------------------------------------------------------------------
1 | pushd
2 | cd __build\llvm\ninja\debug
3 | cmake --build . --config Debug --target install
4 | cmake --install . --config Debug
5 | popd
--------------------------------------------------------------------------------
/scripts/build_llvm_debug_vs.bat:
--------------------------------------------------------------------------------
1 | pushd
2 | cd __build\llvm\msbuild\x64\debug
3 | cmake --build . --config Debug --target install
4 | cmake --install . --config Debug
5 | popd
--------------------------------------------------------------------------------
/scripts/build_llvm_release.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | cd __build/llvm/ninja/release
3 | cmake --build . --config Release --target install -j 8
4 | cmake --install . --config Release
5 |
--------------------------------------------------------------------------------
/scripts/build_llvm_release_ninja.bat:
--------------------------------------------------------------------------------
1 | pushd
2 | cd __build\llvm\ninja\release
3 | cmake --build . --config Release --target install -j 8
4 | cmake --install . --config Release
5 | popd
--------------------------------------------------------------------------------
/scripts/build_llvm_release_vs.bat:
--------------------------------------------------------------------------------
1 | pushd
2 | cd __build\llvm\msbuild\x64\release
3 | cmake --build . --config Release --target install -j 8
4 | cmake --install . --config Release
5 | popd
--------------------------------------------------------------------------------
/scripts/build_llvm_wasm_debug.bat:
--------------------------------------------------------------------------------
1 | pushd
2 | cd __build\llvm\msbuild\wasm\debug
3 | cmake --build . --config Debug --target install -j 8
4 | cmake --install . --config Debug
5 | popd
--------------------------------------------------------------------------------
/scripts/build_llvm_wasm_debug.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | cd __build/llvm/ninja/wasm/debug
3 | cmake --build . --config Debug --target install -j 1
4 | cmake --install . --config Debug
5 |
--------------------------------------------------------------------------------
/scripts/build_llvm_wasm_release.bat:
--------------------------------------------------------------------------------
1 | pushd
2 | cd __build\llvm\msbuild\wasm\release
3 | cmake --build . --config Release --target install -j 8
4 | cmake --install . --config Release
5 | popd
--------------------------------------------------------------------------------
/scripts/build_llvm_wasm_release.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | cd __build/llvm/ninja/wasm/release
3 | cmake --build . --config Release --target install -j 1
4 | cmake --install . --config Release
5 |
--------------------------------------------------------------------------------
/scripts/config_lldb_debug.bat:
--------------------------------------------------------------------------------
1 | pushd
2 | mkdir __build\lldb\ninja\debug
3 | cd __build\lldb\ninja\debug
4 | cmake ..\..\..\..\3rdParty\llvm-project\llvm -G "Ninja" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=../../../../3rdParty/lldb/debug -DLLVM_INSTALL_UTILS=ON -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_PLUGINS=ON -DLLVM_ENABLE_PROJECTS="lldb" -DLLVM_ENABLE_EH=ON -DLLVM_ENABLE_RTTI=ON -DLLVM_REQUIRES_RTTI=ON -DLLVM_ENABLE_PIC=ON
5 | popd
6 |
7 |
--------------------------------------------------------------------------------
/scripts/config_lldb_release.bat:
--------------------------------------------------------------------------------
1 | pushd
2 | mkdir __build\lldb\ninja\release
3 | cd __build\lldb\ninja\release
4 | cmake ..\..\..\..\3rdParty\llvm-project\llvm -G "Ninja" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../../../../3rdParty/lldb/release -DLLVM_INSTALL_UTILS=ON -DLLVM_ENABLE_ASSERTIONS=OFF -DLLVM_ENABLE_PLUGINS=ON -DLLVM_ENABLE_PROJECTS="lldb" -DLLVM_ENABLE_EH=ON -DLLVM_ENABLE_RTTI=ON -DLLVM_REQUIRES_RTTI=ON -DLLVM_ENABLE_PIC=ON
5 | popd
6 |
--------------------------------------------------------------------------------
/scripts/config_llvm_debug.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | mkdir -p __build/llvm/ninja/debug
3 | cd __build/llvm/ninja/debug
4 | cmake ../../../../3rdParty/llvm-project/llvm -G "Ninja" -DLLVM_TARGETS_TO_BUILD="host;ARM;AArch64" -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="WebAssembly" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=../../../../3rdParty/llvm/debug -DLLVM_INSTALL_UTILS=ON -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_PLUGINS=ON -DLLVM_ENABLE_PROJECTS="clang;lld;mlir" -DLLVM_ENABLE_EH=ON -DLLVM_ENABLE_RTTI=ON -DLLVM_REQUIRES_RTTI=ON -DLLVM_ENABLE_PIC=ON
5 |
6 |
--------------------------------------------------------------------------------
/scripts/config_llvm_debug_ninja.bat:
--------------------------------------------------------------------------------
1 | pushd
2 | mkdir __build\llvm\ninja\debug
3 | cd __build\llvm\ninja\debug
4 | cmake ../../../../3rdParty/llvm-project/llvm -G "Ninja" -DLLVM_HOST_TRIPLE=x86_64 -DLLVM_TARGETS_TO_BUILD="host;ARM;AArch64" -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="WebAssembly" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=../../../../3rdParty/llvm/debug -DLLVM_INSTALL_UTILS=ON -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_PLUGINS=ON -DLLVM_ENABLE_PROJECTS="clang;lld;mlir" -DLLVM_ENABLE_EH=ON -DLLVM_ENABLE_RTTI=ON -DLLVM_REQUIRES_RTTI=ON -DLLVM_ENABLE_PIC=ON -Wno-dev
5 | popd
6 |
7 |
--------------------------------------------------------------------------------
/scripts/config_llvm_debug_vs.bat:
--------------------------------------------------------------------------------
1 | pushd
2 | mkdir __build\llvm\msbuild\x64\debug
3 | cd __build\llvm\msbuild\x64\debug
4 | if exist "C:/Program Files/Microsoft Visual Studio/2022/Professional" set EXTRA_PARAM=-DCMAKE_GENERATOR_INSTANCE="C:/Program Files/Microsoft Visual Studio/2022/Professional"
5 | cmake ..\..\..\..\..\3rdParty\llvm-project\llvm -G "Visual Studio 17 2022" -A x64 %EXTRA_PARAM% -DLLVM_TARGETS_TO_BUILD="host;ARM;AArch64" -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="WebAssembly" -DCMAKE_BUILD_TYPE=Debug -Thost=x64 -DCMAKE_INSTALL_PREFIX=../../../../../3rdParty/llvm/x64/debug -DLLVM_INSTALL_UTILS=ON -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_PLUGINS=ON -DLLVM_ENABLE_PROJECTS="clang;lld;mlir" -DLLVM_ENABLE_EH=ON -DLLVM_ENABLE_RTTI=ON -DLLVM_REQUIRES_RTTI=ON -DLLVM_ENABLE_PIC=ON -Wno-dev
6 | popd
7 |
8 |
--------------------------------------------------------------------------------
/scripts/config_llvm_debug_vs19.bat:
--------------------------------------------------------------------------------
1 | pushd
2 | mkdir __build\llvm\msbuild\x64\debug
3 | cd __build\llvm\msbuild\x64\debug
4 | if exist "C:/Program Files/Microsoft Visual Studio/2022/Professional" set EXTRA_PARAM=-DCMAKE_GENERATOR_INSTANCE="C:/Program Files/Microsoft Visual Studio/2022/Professional"
5 | cmake ..\..\..\..\..\3rdParty\llvm-project\llvm -G "Visual Studio 17 2022" -A x64 %EXTRA_PARAM% -DLLVM_TARGETS_TO_BUILD="host;ARM;AArch64" -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="WebAssembly" -DCMAKE_BUILD_TYPE=Debug -T="v142" -DCMAKE_INSTALL_PREFIX=../../../../../3rdParty/llvm/x64/debug -DLLVM_INSTALL_UTILS=ON -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_PLUGINS=ON -DLLVM_ENABLE_PROJECTS="clang;lld;mlir" -DLLVM_ENABLE_EH=ON -DLLVM_ENABLE_RTTI=ON -DLLVM_REQUIRES_RTTI=ON -DLLVM_ENABLE_PIC=ON
6 | popd
7 |
8 |
--------------------------------------------------------------------------------
/scripts/config_llvm_debug_vs_clangcl.bat:
--------------------------------------------------------------------------------
1 | pushd
2 | mkdir __build\llvm\msbuild\x64\debug
3 | cd __build\llvm\msbuild\x64\debug
4 | if exist "C:/Program Files/Microsoft Visual Studio/2022/Professional" set EXTRA_PARAM=-DCMAKE_GENERATOR_INSTANCE="C:/Program Files/Microsoft Visual Studio/2022/Professional"
5 | cmake ..\..\..\..\..\3rdParty\llvm-project\llvm -G "Visual Studio 17 2022" -A x64 %EXTRA_PARAM% -DLLVM_TARGETS_TO_BUILD="host;ARM;AArch64" -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="WebAssembly" -DCMAKE_BUILD_TYPE=Debug -T="ClangCL" -DCMAKE_INSTALL_PREFIX=../../../../../3rdParty/llvm/x64/debug -DLLVM_INSTALL_UTILS=ON -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_PLUGINS=ON -DLLVM_ENABLE_PROJECTS="clang;lld;mlir" -DLLVM_ENABLE_EH=ON -DLLVM_ENABLE_RTTI=ON -DLLVM_REQUIRES_RTTI=ON -DLLVM_ENABLE_PIC=ON
6 | popd
7 |
8 |
--------------------------------------------------------------------------------
/scripts/config_llvm_debug_vs_intel.bat:
--------------------------------------------------------------------------------
1 | pushd
2 | mkdir __build\llvm\msbuild\x64\debug
3 | cd __build\llvm\msbuild\x64\debug
4 | if exist "C:/Program Files/Microsoft Visual Studio/2022/Professional" set EXTRA_PARAM=-DCMAKE_GENERATOR_INSTANCE="C:/Program Files/Microsoft Visual Studio/2022/Professional"
5 | cmake ..\..\..\..\..\3rdParty\llvm-project\llvm -G "Visual Studio 17 2022" -A x64 %EXTRA_PARAM% -DLLVM_TARGETS_TO_BUILD="host;ARM;AArch64" -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="WebAssembly" -DCMAKE_BUILD_TYPE=Debug -T="Intel C++ Compiler 2024" -DCMAKE_INSTALL_PREFIX=../../../../../3rdParty/llvm/x64/debug -DLLVM_INSTALL_UTILS=ON -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_PLUGINS=ON -DLLVM_ENABLE_PROJECTS="clang;lld;mlir" -DLLVM_ENABLE_EH=ON -DLLVM_ENABLE_RTTI=ON -DLLVM_REQUIRES_RTTI=ON -DLLVM_ENABLE_PIC=ON
6 | popd
7 |
8 |
--------------------------------------------------------------------------------
/scripts/config_llvm_release.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | mkdir -p __build/llvm/ninja/release
3 | cd __build/llvm/ninja/release
4 | cmake ../../../../3rdParty/llvm-project/llvm -G "Ninja" -DLLVM_TARGETS_TO_BUILD="host;ARM;AArch64" -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="WebAssembly" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../../../../3rdParty/llvm/release -DLLVM_INSTALL_UTILS=ON -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_PLUGINS=ON -DLLVM_ENABLE_PROJECTS="clang;lld;mlir" -DLLVM_ENABLE_EH=ON -DLLVM_ENABLE_RTTI=ON -DLLVM_REQUIRES_RTTI=ON -DLLVM_ENABLE_PIC=ON
5 |
6 |
--------------------------------------------------------------------------------
/scripts/config_llvm_release_ninja.bat:
--------------------------------------------------------------------------------
1 | pushd
2 | mkdir __build\llvm\ninja\release
3 | cd __build\llvm\ninja\release
4 | cmake ../../../../3rdParty/llvm-project/llvm -G "Ninja" -DLLVM_HOST_TRIPLE=x86_64 -DLLVM_TARGETS_TO_BUILD="host;ARM;AArch64" -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="WebAssembly" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../../../../3rdParty/llvm/release -DLLVM_INSTALL_UTILS=ON -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_PLUGINS=ON -DLLVM_ENABLE_PROJECTS="clang;lld;mlir" -DLLVM_ENABLE_EH=ON -DLLVM_ENABLE_RTTI=ON -DLLVM_REQUIRES_RTTI=ON -DLLVM_ENABLE_PIC=ON -Wno-dev
5 | popd
6 |
--------------------------------------------------------------------------------
/scripts/config_llvm_release_vs.bat:
--------------------------------------------------------------------------------
1 | pushd
2 | mkdir __build\llvm\msbuild\x64\release
3 | cd __build\llvm\msbuild\x64\release
4 | if exist "C:/Program Files/Microsoft Visual Studio/2022/Professional" set EXTRA_PARAM=-DCMAKE_GENERATOR_INSTANCE="C:/Program Files/Microsoft Visual Studio/2022/Professional"
5 | cmake ..\..\..\..\..\3rdParty\llvm-project\llvm -G "Visual Studio 17 2022" -A x64 %EXTRA_PARAM% -DLLVM_TARGETS_TO_BUILD="host;ARM;AArch64" -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="WebAssembly" -DCMAKE_BUILD_TYPE=Release -Thost=x64 -DCMAKE_INSTALL_PREFIX=../../../../../3rdParty/llvm/x64/release -DLLVM_INSTALL_UTILS=ON -DLLVM_ENABLE_ASSERTIONS=OFF -DLLVM_ENABLE_PLUGINS=ON -DLLVM_ENABLE_PROJECTS="clang;lld;mlir" -DLLVM_ENABLE_EH=ON -DLLVM_ENABLE_RTTI=ON -DLLVM_REQUIRES_RTTI=ON -DLLVM_ENABLE_PIC=ON
6 | popd
7 |
--------------------------------------------------------------------------------
/scripts/config_llvm_wasm_debug.bat:
--------------------------------------------------------------------------------
1 | pushd
2 | mkdir __build\llvm\msbuild\wasm\debug
3 | cd __build\llvm\msbuild\wasm\debug
4 | if exist "C:/Program Files/Microsoft Visual Studio/2022/Professional" set EXTRA_PARAM=-DCMAKE_GENERATOR_INSTANCE="C:/Program Files/Microsoft Visual Studio/2022/Professional"
5 | emcmake cmake ..\..\..\..\..\3rdParty\llvm-project\llvm -G "Visual Studio 17 2022" -A x64 -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="WebAssembly" -DCMAKE_BUILD_TYPE=Debug -Thost=x64 -DCMAKE_INSTALL_PREFIX=../../../../../3rdParty/llvm/wasm/debug -DLLVM_INSTALL_UTILS=ON -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_PLUGINS=ON -DLLVM_ENABLE_PROJECTS="mlir" -DLLVM_ENABLE_EH=ON -DLLVM_ENABLE_RTTI=ON -DLLVM_REQUIRES_RTTI=ON -DLLVM_ENABLE_PIC=ON
6 | popd
7 |
8 |
--------------------------------------------------------------------------------
/scripts/config_llvm_wasm_debug.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | mkdir -p __build/llvm/ninja/wasm/debug
3 | cd __build/llvm/ninja/wasm/debug
4 | emcmake cmake ../../../../../3rdParty/llvm-project/llvm -G "Ninja" -DLLVM_TARGETS_TO_BUILD= -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="WebAssembly" -DLLVM_USE_HOST_TOOLS:BOOL=ON -DLLVM_NATIVE_PATH="/home/alex/TypeScriptCompiler/3rdParty/llvm/release/bin" -DCMAKE_HOST_SYSTEM_NAME="Linux" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=../../../../../3rdParty/llvm/wasm/debug -DLLVM_INSTALL_UTILS=ON -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_PLUGINS=ON -DLLVM_ENABLE_PROJECTS="mlir" -DLLVM_ENABLE_EH=ON -DLLVM_ENABLE_RTTI=ON -DLLVM_REQUIRES_RTTI=ON -DLLVM_ENABLE_PIC=ON
--------------------------------------------------------------------------------
/scripts/config_llvm_wasm_release.bat:
--------------------------------------------------------------------------------
1 | pushd
2 | mkdir __build\llvm\msbuild\wasm\release
3 | cd __build\llvm\msbuild\wasm\release
4 | if exist "C:/Program Files/Microsoft Visual Studio/2022/Professional" set EXTRA_PARAM=-DCMAKE_GENERATOR_INSTANCE="C:/Program Files/Microsoft Visual Studio/2022/Professional"
5 | emcmake cmake ..\..\..\..\..\3rdParty\llvm-project\llvm -G "Visual Studio 17 2022" -A x64 -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="WebAssembly" -DCMAKE_BUILD_TYPE=Release -Thost=x64 -DCMAKE_INSTALL_PREFIX=../../../../../3rdParty/llvm/wasm/release -DLLVM_INSTALL_UTILS=ON -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_PLUGINS=ON -DLLVM_ENABLE_PROJECTS="mlir" -DLLVM_ENABLE_EH=ON -DLLVM_ENABLE_RTTI=ON -DLLVM_REQUIRES_RTTI=ON -DLLVM_ENABLE_PIC=ON
6 | popd
7 |
8 |
--------------------------------------------------------------------------------
/scripts/config_llvm_wasm_release.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | mkdir -p __build/llvm/ninja/wasm/release
3 | cd __build/llvm/ninja/wasm/release
4 | emcmake cmake ../../../../../3rdParty/llvm-project/llvm -G "Ninja" -DLLVM_TARGETS_TO_BUILD= -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="WebAssembly" -DLLVM_USE_HOST_TOOLS:BOOL=ON -DLLVM_NATIVE_PATH="/home/alex/TypeScriptCompiler/3rdParty/llvm/release/bin" -DCMAKE_HOST_SYSTEM_NAME="Linux" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../../../../../3rdParty/llvm/wasm/release -DLLVM_INSTALL_UTILS=ON -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_PLUGINS=ON -DLLVM_ENABLE_PROJECTS="mlir" -DLLVM_ENABLE_EH=ON -DLLVM_ENABLE_RTTI=ON -DLLVM_REQUIRES_RTTI=ON -DLLVM_ENABLE_PIC=ON
--------------------------------------------------------------------------------
/tag.bat:
--------------------------------------------------------------------------------
1 | git tag -a v0.0-pre-alpha72 -m "pre alpha v0.0-72"
2 | git push origin --tags
3 |
--------------------------------------------------------------------------------
/tag_del.bat:
--------------------------------------------------------------------------------
1 | git push --delete origin v0.0-pre-alpha72
2 | git tag -d v0.0-pre-alpha72
3 |
--------------------------------------------------------------------------------
/tsc/build_tsc_debug-test.bat:
--------------------------------------------------------------------------------
1 | pushd
2 | cd ../__build/tsc/windows-msbuild-debug
3 | set CTEST_OUTPUT_ON_FAILURE=TRUE
4 | set CTEST_PARALLEL_LEVEL=16
5 | cmake --build . --target RUN_TESTS --config Debug --parallel
6 | popd
--------------------------------------------------------------------------------
/tsc/build_tsc_debug-unittests.bat:
--------------------------------------------------------------------------------
1 | pushd
2 | cd ../__build/tsc/msbuild/x64/debug
3 | cmake --build . --target MLIRTypeScriptUnitTests --config Debug -j 16
4 | popd
--------------------------------------------------------------------------------
/tsc/build_tsc_debug.bat:
--------------------------------------------------------------------------------
1 | pushd
2 | cd ../__build/tsc/msbuild/x64/debug
3 | cmake --build . --config Debug -j 24
4 | popd
--------------------------------------------------------------------------------
/tsc/build_tsc_debug.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | cd ../__build/tsc/ninja/debug
3 | cmake --build . --config Debug -j 8
4 | bash -f ../../../../scripts/separate_debug_info.sh ./bin/tsc
5 |
--------------------------------------------------------------------------------
/tsc/build_tsc_defaultlib_debug.bat:
--------------------------------------------------------------------------------
1 | pushd
2 | cd ../../TypeScriptCompilerDefaultLib/
3 | call build.bat
4 |
5 | xcopy dll\*.* "../TypeScriptCompiler/__build/tsc/windows-msbuild-debug/bin/defaultlib/dll/" /i /y
6 | xcopy lib\*.* "../TypeScriptCompiler/__build/tsc/windows-msbuild-debug/bin/defaultlib/lib/" /i /y
7 | xcopy src\*.d.ts "../TypeScriptCompiler/__build/tsc/windows-msbuild-debug/bin/defaultlib/" /i /y
8 |
9 | popd
10 |
--------------------------------------------------------------------------------
/tsc/build_tsc_release-test.bat:
--------------------------------------------------------------------------------
1 | pushd
2 | cd ../__build/tsc/msbuild/x64/release
3 | cmake --build . --config Release -j 24
4 | set CTEST_OUTPUT_ON_FAILURE=TRUE
5 | cmake --build . --target RUN_TESTS --config Release -j 24
6 | popd
--------------------------------------------------------------------------------
/tsc/build_tsc_release-test.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | cd ../__build/tsc/ninja/release
3 | ctest -j18 -C Release -T test --output-on-failure -T test --output-on-failure
--------------------------------------------------------------------------------
/tsc/build_tsc_release.bat:
--------------------------------------------------------------------------------
1 | pushd
2 | cd ../__build/tsc/msbuild/x64/release
3 | cmake --build . --config Release -j 24
4 | popd
--------------------------------------------------------------------------------
/tsc/build_tsc_release.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | cd ../__build/tsc/ninja/release
3 | cmake --build . --config Release -j 8
4 |
--------------------------------------------------------------------------------
/tsc/config_tsc_debug.bat:
--------------------------------------------------------------------------------
1 | pushd
2 | mkdir "../__build/tsc/msbuild/x64/debug"
3 | cd "../__build/tsc/msbuild/x64/debug"
4 | if exist "C:/Program Files/Microsoft Visual Studio/2022/Professional" set EXTRA_PARAM=-DCMAKE_GENERATOR_INSTANCE="C:/Program Files/Microsoft Visual Studio/2022/Professional"
5 | cmake ../../../../../tsc -G "Visual Studio 17 2022" -A x64 -DCMAKE_BUILD_TYPE=Debug -DTSC_PACKAGE_VERSION:STRING=1.2.3 -DTYPESCRIPT_INCLUDE_TESTS=any -Wno-dev %EXTRA_PARAM%
6 | popd
7 |
--------------------------------------------------------------------------------
/tsc/config_tsc_debug.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | mkdir -p ../__build/tsc/ninja/debug
3 | cd ../__build/tsc/ninja/debug
4 | cmake ../../../../tsc -G "Ninja" -DCMAKE_BUILD_TYPE=Debug -Wno-dev
5 |
6 |
--------------------------------------------------------------------------------
/tsc/config_tsc_release.bat:
--------------------------------------------------------------------------------
1 | pushd
2 | mkdir "../__build/tsc/msbuild/x64/release"
3 | cd "../__build/tsc/msbuild/x64/release"
4 | if exist "C:/Program Files/Microsoft Visual Studio/2022/Professional" set EXTRA_PARAM=-DCMAKE_GENERATOR_INSTANCE="C:/Program Files/Microsoft Visual Studio/2022/Professional"
5 | cmake ../../../../../tsc -G "Visual Studio 17 2022" -A x64 -DCMAKE_BUILD_TYPE=Release -Wno-dev %EXTRA_PARAM%
6 | popd
7 |
--------------------------------------------------------------------------------
/tsc/config_tsc_release.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | mkdir -p ../__build/tsc/ninja/release
3 | cd ../__build/tsc/ninja/release
4 | cmake ../../../../tsc -G "Ninja" -DCMAKE_BUILD_TYPE=Release -Wno-dev
5 |
6 |
--------------------------------------------------------------------------------
/tsc/include/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "cmake.configureOnOpen": false
3 | }
--------------------------------------------------------------------------------
/tsc/include/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | add_subdirectory(TypeScript)
2 |
--------------------------------------------------------------------------------
/tsc/include/TypeScript/AsyncDialectTranslation.h:
--------------------------------------------------------------------------------
1 | #ifndef MLIR_TARGET_LLVMIR_DIALECT_TYPESCRIPT_ASYNCDIALECTTRANSLATION_H
2 | #define MLIR_TARGET_LLVMIR_DIALECT_TYPESCRIPT_ASYNCDIALECTTRANSLATION_H
3 |
4 | namespace mlir
5 | {
6 |
7 | class DialectRegistry;
8 | class MLIRContext;
9 |
10 | namespace typescript
11 | {
12 | void registerAsyncDialectTranslation(DialectRegistry ®istry);
13 |
14 | void registerAsyncDialectTranslation(MLIRContext &context);
15 | } // namespace typescript
16 |
17 | } // namespace mlir
18 |
19 | #endif // MLIR_TARGET_LLVMIR_DIALECT_TYPESCRIPT_ASYNCDIALECTTRANSLATION_H
20 |
--------------------------------------------------------------------------------
/tsc/include/TypeScript/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | add_mlir_dialect(TypeScriptOps ts)
2 | add_mlir_doc(TypeScriptDialect -gen-dialect-doc Dialect TypeScript/)
3 | add_mlir_doc(TypeScriptOps -gen-op-doc TypeScriptOps TypeScript/)
4 |
--------------------------------------------------------------------------------
/tsc/include/TypeScript/DataStructs.h:
--------------------------------------------------------------------------------
1 | #ifndef TYPESCRIPT_DATASTRUCT_H_
2 | #define TYPESCRIPT_DATASTRUCT_H_
3 |
4 | #include "TypeScript/TypeScriptCompiler/Defines.h"
5 |
6 | #include
7 |
8 | struct CompileOptions
9 | {
10 | bool isJit;
11 | bool disableGC;
12 | bool enableBuiltins;
13 | bool noDefaultLib;
14 | std::string defaultDeclarationTSFile;
15 | bool disableWarnings;
16 | bool generateDebugInfo;
17 | bool lldbDebugInfo;
18 | std::string moduleTargetTriple;
19 | int sizeBits;
20 | bool isWasm;
21 | bool isWindows;
22 | bool isExecutable;
23 | bool isDLL;
24 | enum Exports exportOpt;
25 | bool embedExportDeclarations;
26 | std::string outputFolder;
27 | bool appendGCtorsToMethod;
28 | bool strictNullChecks;
29 | };
30 |
31 | #endif // TYPESCRIPT_DATASTRUCT_H_
--------------------------------------------------------------------------------
/tsc/include/TypeScript/DiagnosticHelper.h:
--------------------------------------------------------------------------------
1 | #ifndef MLIR_DIAGNOSTIC_HELPER_H_
2 | #define MLIR_DIAGNOSTIC_HELPER_H_
3 |
4 | #include "mlir/IR/Diagnostics.h"
5 | #include "llvm/ADT/SmallVector.h"
6 | #include "llvm/Support/raw_ostream.h"
7 |
8 | class SourceMgrDiagnosticHandlerEx : public mlir::SourceMgrDiagnosticHandler
9 | {
10 | public:
11 | SourceMgrDiagnosticHandlerEx(llvm::SourceMgr &mgr, mlir::MLIRContext *ctx);
12 | void emit(mlir::Diagnostic &diag);
13 | };
14 |
15 | void printDiagnostics(SourceMgrDiagnosticHandlerEx &, mlir::SmallVector> &, bool);
16 | void printLocation(llvm::raw_ostream &, mlir::Location, llvm::StringRef, bool suppressSeparator = false);
17 |
18 | #endif // MLIR_DIAGNOSTIC_HELPER_H_
19 |
--------------------------------------------------------------------------------
/tsc/include/TypeScript/Helper.h:
--------------------------------------------------------------------------------
1 | #ifndef TYPESCRIPT_HELPER_H
2 | #define TYPESCRIPT_HELPER_H
3 |
4 | #include
5 |
6 | template< typename T, typename U >
7 | inline std::unique_ptr< T > dynamic_pointer_cast(std::unique_ptr< U > &&ptr) {
8 | U * const stored_ptr = ptr.release();
9 | T * const converted_stored_ptr = dynamic_cast< T * >(stored_ptr);
10 | if (converted_stored_ptr) {
11 | return std::unique_ptr< T >(converted_stored_ptr);
12 | }
13 | else {
14 | if (stored_ptr)
15 | {
16 | throw "Invalid cast";
17 | }
18 |
19 | ptr.reset(stored_ptr);
20 | return std::unique_ptr< T >();
21 | }
22 | }
23 |
24 | #endif // TYPESCRIPT_HELPER_H
--------------------------------------------------------------------------------
/tsc/include/TypeScript/MLIRLogic/MLIRLocationGuard.h:
--------------------------------------------------------------------------------
1 | #ifndef MLIR_TYPESCRIPT_COMMONGENLOGIC_MLIRLOCATIONGUARD_H_
2 | #define MLIR_TYPESCRIPT_COMMONGENLOGIC_MLIRLOCATIONGUARD_H_
3 |
4 | namespace typescript
5 | {
6 |
7 | class MLIRLocationGuard
8 | {
9 | mlir::Location &value;
10 | mlir::Location savedValue;
11 |
12 | public:
13 | MLIRLocationGuard(mlir::Location &value) : value(value), savedValue(value)
14 | {
15 | }
16 |
17 | ~MLIRLocationGuard()
18 | {
19 | value = savedValue;
20 | }
21 | };
22 |
23 | } // namespace typescript
24 |
25 | #endif // MLIR_TYPESCRIPT_COMMONGENLOGIC_MLIRLOCATIONGUARD_H_
26 |
--------------------------------------------------------------------------------
/tsc/include/TypeScript/MLIRLogic/MLIRNamespaceGuard.h:
--------------------------------------------------------------------------------
1 | #ifndef MLIR_TYPESCRIPT_COMMONGENLOGIC_MLIRNAMESPACEGUARD_H_
2 | #define MLIR_TYPESCRIPT_COMMONGENLOGIC_MLIRNAMESPACEGUARD_H_
3 |
4 | #include "TypeScript/TypeScriptOps.h"
5 |
6 | #include "parser.h"
7 |
8 | namespace mlir_ts = mlir::typescript;
9 |
10 | namespace typescript
11 | {
12 |
13 | class MLIRNamespaceGuard
14 | {
15 | NamespaceInfo::TypePtr savedNamespace;
16 | NamespaceInfo::TypePtr ¤tNamespace;
17 |
18 | public:
19 | MLIRNamespaceGuard(NamespaceInfo::TypePtr ¤tNamespace) : currentNamespace(currentNamespace)
20 | {
21 | savedNamespace = currentNamespace;
22 | }
23 |
24 | ~MLIRNamespaceGuard()
25 | {
26 | currentNamespace = savedNamespace;
27 | }
28 | };
29 |
30 | } // namespace typescript
31 |
32 | #endif // MLIR_TYPESCRIPT_COMMONGENLOGIC_MLIRNAMESPACEGUARD_H_
33 |
--------------------------------------------------------------------------------
/tsc/include/TypeScript/MLIRLogic/MLIRValueGuard.h:
--------------------------------------------------------------------------------
1 | #ifndef MLIR_TYPESCRIPT_COMMONGENLOGIC_MLIRVALUEGUARD_H_
2 | #define MLIR_TYPESCRIPT_COMMONGENLOGIC_MLIRVALUEGUARD_H_
3 |
4 | namespace typescript
5 | {
6 |
7 | template
8 | class MLIRValueGuard
9 | {
10 | T &value;
11 | T savedValue;
12 |
13 | public:
14 | MLIRValueGuard(T &value) : value(value)
15 | {
16 | savedValue = value;
17 | }
18 |
19 | ~MLIRValueGuard()
20 | {
21 | value = savedValue;
22 | }
23 | };
24 |
25 | } // namespace typescript
26 |
27 | #endif // MLIR_TYPESCRIPT_COMMONGENLOGIC_MLIRNAMESPACEGUARD_H_
28 |
--------------------------------------------------------------------------------
/tsc/include/TypeScript/Pass/AliasPass.h:
--------------------------------------------------------------------------------
1 | #ifndef ALIAS_PASS__H
2 | #define ALIAS_PASS__H
3 |
4 | #include "llvm/Pass.h"
5 | #include "llvm/IR/PassManager.h"
6 |
7 | namespace ts
8 | {
9 | class AliasPass : public llvm::PassInfoMixin
10 | {
11 | private:
12 | bool isWasm;
13 | size_t intSize;
14 |
15 | public:
16 | AliasPass(bool isWasm, size_t intSize) : isWasm(isWasm), intSize(intSize) {
17 | }
18 |
19 | llvm::PreservedAnalyses run(llvm::Module &M, llvm::ModuleAnalysisManager &MAM);
20 |
21 | static bool isRequired()
22 | {
23 | return true;
24 | }
25 | };
26 | }
27 |
28 | #endif // ALIAS_PASS__H
29 |
--------------------------------------------------------------------------------
/tsc/include/TypeScript/Pass/DebugInfoPatchPass.h:
--------------------------------------------------------------------------------
1 | #ifndef DEBUGINFO_PATCH_PASS__H
2 | #define DEBUGINFO_PATCH_PASS__H
3 |
4 | #include "llvm/Pass.h"
5 | #include "llvm/IR/PassManager.h"
6 |
7 | namespace ts
8 | {
9 | class DebugInfoPatchPass : public llvm::PassInfoMixin
10 | {
11 | public:
12 | llvm::PreservedAnalyses run(llvm::Function &F, llvm::FunctionAnalysisManager &AM);
13 |
14 | static bool isRequired()
15 | {
16 | return true;
17 | }
18 | };
19 | }
20 |
21 | #endif // DEBUGINFO_PATCH_PASS__H
22 |
--------------------------------------------------------------------------------
/tsc/include/TypeScript/Pass/ExportFixPass.h:
--------------------------------------------------------------------------------
1 | #ifndef EXPORT_FIX_PASS__H
2 | #define EXPORT_FIX_PASS__H
3 |
4 | #include "llvm/Pass.h"
5 | #include "llvm/IR/PassManager.h"
6 |
7 | namespace ts
8 | {
9 | class ExportFixPass : public llvm::PassInfoMixin
10 | {
11 | private:
12 | bool isWindowsMSVCEnvironment;
13 |
14 | public:
15 | ExportFixPass(bool isWindowsMSVCEnvironment) : isWindowsMSVCEnvironment(isWindowsMSVCEnvironment) {
16 | }
17 |
18 | llvm::PreservedAnalyses run(llvm::Module &M, llvm::ModuleAnalysisManager &MAM);
19 |
20 | static bool isRequired()
21 | {
22 | return true;
23 | }
24 | };
25 | }
26 |
27 | #endif // EXPORT_FIX_PASS__H
28 |
--------------------------------------------------------------------------------
/tsc/include/TypeScript/Pass/LandingPadFixPass.h:
--------------------------------------------------------------------------------
1 | #ifndef LANDINGPAD_FIX_PASS__H
2 | #define LANDINGPAD_FIX_PASS__H
3 |
4 | #include "llvm/Pass.h"
5 | #include "llvm/IR/PassManager.h"
6 |
7 | namespace ts
8 | {
9 | class LandingPadFixPass : public llvm::PassInfoMixin
10 | {
11 | public:
12 | llvm::PreservedAnalyses run(llvm::Function &F, llvm::FunctionAnalysisManager &AM);
13 |
14 | static bool isRequired()
15 | {
16 | return true;
17 | }
18 | };
19 | }
20 |
21 | #endif // LANDINGPAD_FIX_PASS__H
22 |
--------------------------------------------------------------------------------
/tsc/include/TypeScript/Pass/MemAllocFixPass.h:
--------------------------------------------------------------------------------
1 | #ifndef MEMALLOCFIX_PASS__H
2 | #define MEMALLOCFIX_PASS__H
3 |
4 | #include "llvm/Pass.h"
5 | #include "llvm/IR/PassManager.h"
6 |
7 | namespace ts
8 | {
9 | class MemAllocFixPass : public llvm::PassInfoMixin
10 | {
11 | private:
12 | int intSize;
13 |
14 | public:
15 | MemAllocFixPass(int intSize) : intSize(intSize) {}
16 |
17 | llvm::PreservedAnalyses run(llvm::Module &M, llvm::ModuleAnalysisManager &MAM);
18 |
19 | static bool isRequired()
20 | {
21 | return true;
22 | }
23 | };
24 | }
25 |
26 | #endif // MEMALLOCFIX_PASS__H
27 |
--------------------------------------------------------------------------------
/tsc/include/TypeScript/Pass/Win32ExceptionPass.h:
--------------------------------------------------------------------------------
1 | #ifndef WIN32EXCEPTIONPASS__H
2 | #define WIN32EXCEPTIONPASS__H
3 |
4 | #include "llvm/Pass.h"
5 | #include "llvm/IR/PassManager.h"
6 |
7 | namespace ts
8 | {
9 | class Win32ExceptionPass : public llvm::PassInfoMixin
10 | {
11 | public:
12 | llvm::PreservedAnalyses run(llvm::Function &F, llvm::FunctionAnalysisManager &AM);
13 |
14 | static bool isRequired()
15 | {
16 | return true;
17 | }
18 | };
19 | }
20 |
21 | #endif // WIN32EXCEPTIONPASS__H
22 |
--------------------------------------------------------------------------------
/tsc/include/TypeScript/TypeScriptCompiler/Defines.h:
--------------------------------------------------------------------------------
1 | #ifndef TYPESCRIPT_COMPILER_DEFINES_H_
2 | #define TYPESCRIPT_COMPILER_DEFINES_H_
3 |
4 | enum Action
5 | {
6 | ActionNotSet,
7 | DumpAST,
8 | DumpMLIR,
9 | DumpMLIRAffine,
10 | DumpMLIRLLVM,
11 | DumpLLVMIR,
12 | DumpByteCode,
13 | DumpObj,
14 | DumpAssembly,
15 | BuildExe,
16 | BuildDll,
17 | RunJIT
18 | };
19 |
20 | enum Exports
21 | {
22 | ExportsNotSet,
23 | ExportAll,
24 | IgnoreAll
25 | };
26 |
27 | #endif // TYPESCRIPT_COMPILER_DEFINES_H_
--------------------------------------------------------------------------------
/tsc/include/TypeScript/TypeScriptDialect.h:
--------------------------------------------------------------------------------
1 | #ifndef TYPESCRIPT_TYPESCRIPTDIALECT_H
2 | #define TYPESCRIPT_TYPESCRIPTDIALECT_H
3 |
4 | #include "mlir/IR/Dialect.h"
5 |
6 | #include "TypeScript/TypeScriptOpsDialect.h.inc"
7 |
8 | #endif // TYPESCRIPT_TYPESCRIPTDIALECT_H
9 |
--------------------------------------------------------------------------------
/tsc/include/TypeScript/TypeScriptDialectTranslation.h:
--------------------------------------------------------------------------------
1 | #ifndef MLIR_TARGET_LLVMIR_DIALECT_TYPESCRIPT_TYPESCRIPTTOLLVMIRTRANSLATION_H
2 | #define MLIR_TARGET_LLVMIR_DIALECT_TYPESCRIPT_TYPESCRIPTTOLLVMIRTRANSLATION_H
3 |
4 | namespace mlir
5 | {
6 |
7 | class DialectRegistry;
8 | class MLIRContext;
9 |
10 | namespace typescript
11 | {
12 | /// Register the TypeScript dialect and the translation from it to the LLVM IR in the
13 | /// given registry;
14 | void registerTypeScriptDialectTranslation(DialectRegistry ®istry);
15 |
16 | /// Register the TypeScript dialect and the translation from it in the registry
17 | /// associated with the given context.
18 | void registerTypeScriptDialectTranslation(MLIRContext &context);
19 | } // namespace typescript
20 |
21 | } // namespace mlir
22 |
23 | #endif // MLIR_TARGET_LLVMIR_DIALECT_TYPESCRIPT_TYPESCRIPTTOLLVMIRTRANSLATION_H
24 |
--------------------------------------------------------------------------------
/tsc/include/TypeScript/TypeScriptGC.h:
--------------------------------------------------------------------------------
1 | #ifndef MLIR_TYPESCRIPT_GC_H
2 | #define MLIR_TYPESCRIPT_GC_H
3 |
4 | namespace mlir
5 | {
6 |
7 | namespace typescript
8 | {
9 |
10 | void registerTypeScriptGC();
11 | void registerTypeScriptGCStrategy();
12 | void registerTypeScriptGCPrinter();
13 |
14 | } // namespace typescript
15 |
16 | } // namespace mlir
17 |
18 | #endif // MLIR_TYPESCRIPT_GC_H
19 |
--------------------------------------------------------------------------------
/tsc/include/TypeScript/TypeScriptInterfaces.td:
--------------------------------------------------------------------------------
1 | #ifndef TYPESCRIPT_INTERFACESDEFS
2 | #define TYPESCRIPT_INTERFACESDEFS
3 |
4 | include "mlir/IR/OpBase.td"
5 |
6 | //===----------------------------------------------------------------------===//
7 | // TypeScript types definition.
8 | //===----------------------------------------------------------------------===//
9 |
10 | // To get the typescript dialect def.
11 | include "TypeScriptDialect.td"
12 |
13 | #endif // TYPESCRIPT_INTERFACESDEFS
14 |
--------------------------------------------------------------------------------
/tsc/include/TypeScript/TypeScriptLang/TextDiagnostic.h:
--------------------------------------------------------------------------------
1 | #ifndef TYPESCRIPT_TEXTDIAGNOSTIC_H
2 | #define TYPESCRIPT_TEXTDIAGNOSTIC_H
3 |
4 | #include "clang/Basic/Diagnostic.h"
5 | #include "llvm/ADT/IntrusiveRefCntPtr.h"
6 |
7 | namespace typescript::tslang {
8 |
9 | class TextDiagnostic {
10 | public:
11 | TextDiagnostic();
12 |
13 | ~TextDiagnostic();
14 |
15 | static void printDiagnosticLevel(llvm::raw_ostream &os,
16 | clang::DiagnosticsEngine::Level level,
17 | bool showColors);
18 |
19 | static void printDiagnosticMessage(llvm::raw_ostream &os, bool isSupplemental,
20 | llvm::StringRef message, bool showColors);
21 | };
22 |
23 | } // namespace typescript::tslang
24 |
25 | #endif
26 |
--------------------------------------------------------------------------------
/tsc/include/TypeScript/Version.h:
--------------------------------------------------------------------------------
1 | #ifndef TSC_PACKAGE_VERSION
2 | #define TSC_PACKAGE_VERSION "0.0.0-not-set"
3 | #endif
--------------------------------------------------------------------------------
/tsc/include/TypeScript/gcwrapper.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | void _mlir__GC_init();
5 |
6 | void *_mlir__GC_malloc(size_t size);
7 |
8 | void *_mlir__GC_malloc_atomic(size_t size);
9 |
10 | void *_mlir__GC_memalign(size_t align, size_t size);
11 |
12 | void *_mlir__GC_realloc(void *ptr, size_t size);
13 |
14 | void _mlir__GC_free(void *ptr);
15 |
16 | size_t _mlir__GC_get_heap_size();
17 |
18 | void _mlir__GC_win32_free_heap();
19 |
20 | void *_mlir__GC_malloc_explicitly_typed(size_t size, int64_t descr);
21 |
22 | int64_t _mlir__GC_make_descriptor(const int64_t *descr, size_t size);
23 |
--------------------------------------------------------------------------------
/tsc/lib/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "cmake.configureOnOpen": false
3 | }
--------------------------------------------------------------------------------
/tsc/lib/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | add_subdirectory(TypeScript)
2 | #add_subdirectory(TypeScriptGC)
3 | add_subdirectory(TypeScriptExceptionPass)
4 | add_subdirectory(TypeScriptDebugInfoPass)
5 | add_subdirectory(TypeScriptExportPass)
6 | add_subdirectory(TypeScriptRuntime)
7 | add_subdirectory(TypeScriptAsyncRuntime)
8 | add_subdirectory(TypeScriptAliasPass)
9 | add_subdirectory(TypeScriptMemAllocPass)
10 |
--------------------------------------------------------------------------------
/tsc/lib/TypeScript/AsyncDialectTranslation.cpp:
--------------------------------------------------------------------------------
1 | #include "TypeScript/AsyncDialectTranslation.h"
2 |
3 | #include "mlir/Dialect/Async/IR/Async.h"
4 | #include "mlir/IR/Dialect.h"
5 |
6 | using namespace mlir;
7 | using namespace ::typescript;
8 | namespace mlir_ts = mlir::typescript;
9 |
10 | /// Add all the MLIR dialects to the provided registry.
11 | void mlir::typescript::registerAsyncDialectTranslation(DialectRegistry ®istry)
12 | {
13 | registry.insert();
14 | }
15 |
16 | /// Append all the MLIR dialects to the registry contained in the given context.
17 | void mlir::typescript::registerAsyncDialectTranslation(MLIRContext &context)
18 | {
19 | DialectRegistry registry;
20 | registerAsyncDialectTranslation(registry);
21 | context.appendDialectRegistry(registry);
22 | }
--------------------------------------------------------------------------------
/tsc/lib/TypeScript/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | message(STATUS ">>> lib >>> TypeScript")
2 |
3 | set_Options()
4 |
5 | include_directories(
6 | ${PROJECT_SOURCE_DIR}/tsc-new-parser
7 | )
8 |
9 | link_directories(
10 | ${PROJECT_SOURCE_DIR}/tsc-new-parser
11 | )
12 |
13 | add_mlir_dialect_library(MLIRTypeScript
14 | TypeScriptDialect.cpp
15 | TypeScriptOps.cpp
16 | TypeScriptDialectTranslation.cpp
17 | AsyncDialectTranslation.cpp
18 | DiagnosticHelper.cpp
19 | MLIRGen.cpp
20 | LowerToAffineLoops.cpp
21 | LowerToLLVM.cpp
22 | RelocateConstantPass.cpp
23 | GCPass.cpp
24 | ObjDumper.cpp
25 | DeclarationPrinter.cpp
26 |
27 | ADDITIONAL_HEADER_DIRS
28 | ${PROJECT_SOURCE_DIR}/tsc-new-parser
29 |
30 | DEPENDS
31 | MLIRTypeScriptOpsIncGen
32 |
33 | LINK_LIBS PUBLIC
34 | tsc-new-parser-lib
35 | MLIRIR
36 | )
37 |
--------------------------------------------------------------------------------
/tsc/lib/TypeScriptAliasPass/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | set(LLVM_LINK_COMPONENTS
2 | Analysis
3 | Core
4 | Support
5 | )
6 |
7 | add_llvm_library(TypeScriptAliasPass
8 | AliasPass.cpp
9 |
10 | ADDITIONAL_HEADER_DIRS
11 |
12 | DEPENDS
13 | intrinsics_gen
14 | )
15 |
--------------------------------------------------------------------------------
/tsc/lib/TypeScriptAsyncRuntime/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | if(MSVC)
2 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR")
3 | else()
4 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -frtti")
5 | endif()
6 |
7 | add_mlir_library(TypeScriptAsyncRuntime
8 | STATIC
9 | AsyncRuntime.cpp
10 |
11 | EXCLUDE_FROM_LIBMLIR
12 | )
13 |
--------------------------------------------------------------------------------
/tsc/lib/TypeScriptDebugInfoPass/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | set(LLVM_LINK_COMPONENTS
2 | Analysis
3 | Core
4 | Support
5 | )
6 |
7 | add_llvm_library(TypeScriptDebugInfoPass
8 | DebugInfoPatchPass.cpp
9 |
10 | ADDITIONAL_HEADER_DIRS
11 |
12 | DEPENDS
13 | intrinsics_gen
14 | )
15 |
--------------------------------------------------------------------------------
/tsc/lib/TypeScriptExceptionPass/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | set(LLVM_LINK_COMPONENTS
2 | Analysis
3 | Core
4 | Support
5 | )
6 |
7 | add_llvm_library(TypeScriptExceptionPass
8 | Win32ExceptionPass.cpp
9 | LandingPadFixPass.cpp
10 |
11 | ADDITIONAL_HEADER_DIRS
12 |
13 | DEPENDS
14 | intrinsics_gen
15 | )
16 |
--------------------------------------------------------------------------------
/tsc/lib/TypeScriptExportPass/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | set(LLVM_LINK_COMPONENTS
2 | Analysis
3 | Core
4 | Support
5 | )
6 |
7 | add_llvm_library(TypeScriptExportPass
8 | ExportFixPass.cpp
9 |
10 | ADDITIONAL_HEADER_DIRS
11 |
12 | DEPENDS
13 | intrinsics_gen
14 | )
15 |
--------------------------------------------------------------------------------
/tsc/lib/TypeScriptMemAllocPass/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | set(LLVM_LINK_COMPONENTS
2 | Analysis
3 | Core
4 | Support
5 | )
6 |
7 | add_llvm_library(TypeScriptMemAllocPass
8 | MemAllocFixPass.cpp
9 |
10 | ADDITIONAL_HEADER_DIRS
11 |
12 | DEPENDS
13 | intrinsics_gen
14 | )
15 |
--------------------------------------------------------------------------------
/tsc/test/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "cmake.configureOnOpen": false
3 | }
--------------------------------------------------------------------------------
/tsc/test/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | add_subdirectory(tester)
2 | add_subdirectory(print-tester)
3 |
--------------------------------------------------------------------------------
/tsc/test/print-tester/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | set_Options()
2 |
3 | include_directories(
4 | ${PROJECT_SOURCE_DIR}/tsc-new-parser
5 | )
6 |
7 | link_directories(
8 | ${PROJECT_SOURCE_DIR}/tsc-new-parser
9 | )
10 |
11 | set (LIBS "${LIBS}" tsc-new-parser-lib)
12 |
13 | add_executable(printer-tester printer-tester.cpp)
14 | target_link_libraries(printer-tester PRIVATE ${LIBS})
15 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00any_compare.ts:
--------------------------------------------------------------------------------
1 | const a: any = 1;
2 | const b: any = 1;
3 |
4 | print(a == b);
5 |
6 | assert(a == b);
7 |
8 | a = 2;
9 |
10 | print(a == b);
11 |
12 | assert(a != b);
13 |
14 | b = 2;
15 |
16 | print(a == b);
17 |
18 | assert(a == b);
19 |
20 | print("done.");
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00any_generic_equals.ts:
--------------------------------------------------------------------------------
1 | namespace EqualityHelper
2 | {
3 | function equals(l: K, r: K): boolean {
4 | if (typeof(l) == "string")
5 | {
6 | return l == r;
7 | }
8 |
9 | return l == r;
10 | }
11 | }
12 |
13 | const s = "asd";
14 | const a: any = "bsd";
15 | const n = 10.0;
16 | const an: any = n;
17 |
18 | print(EqualityHelper.equals(s, s));
19 | print(EqualityHelper.equals(a, a));
20 | print(EqualityHelper.equals(n, n));
21 |
22 | assert(EqualityHelper.equals(a, a));
23 |
24 | assert(!EqualityHelper.equals(a, an));
25 |
26 | print("done.");
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00array.ts:
--------------------------------------------------------------------------------
1 | function main() {
2 | const ac = [1, 2, 3];
3 | let a = ac;
4 | print(ac[0]);
5 | print(ac[1]);
6 | print(ac[2]);
7 | print(a[0]);
8 | print(a[1]);
9 | print(a[2]);
10 |
11 | const ac2 = [1.0, 2.0, 3.0];
12 | let a2 = ac2;
13 | print(ac2[0]);
14 | print(ac2[1]);
15 | print(ac2[2]);
16 |
17 | print(a2[0]);
18 | print(a2[1]);
19 | print(a2[2]);
20 |
21 | const ac3 = ["item 1", "item 2", "item 3"];
22 | let a3 = ac3;
23 | print(ac3[0]);
24 | print(ac3[1]);
25 | print(ac3[2]);
26 |
27 | print(a3[0]);
28 | print(a3[1]);
29 | print(a3[2]);
30 |
31 | print("done.");
32 | }
33 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00array2.ts:
--------------------------------------------------------------------------------
1 | function main() {
2 | const ac = [1, 2, 3];
3 | let a = ac;
4 | a[1] = 9;
5 |
6 | const ac2 = [1.0, 2.0, 3.0];
7 | let a2 = ac2;
8 | a2[1] = 9.0;
9 |
10 | const ac3 = ["item 1", "item 2", "item 3"];
11 | let a3 = ac3;
12 | a3[1] = "save";
13 |
14 | print("done.");
15 | }
16 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00array3.ts:
--------------------------------------------------------------------------------
1 | function main() {
2 | // example 1
3 | const trees = [[1], [2, 3], [4, 5, 6]];
4 |
5 | for (const a of trees) {
6 | print("array");
7 | for (const b of a) {
8 | print(b);
9 | }
10 | }
11 |
12 | // example 2
13 | const x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
14 | const a = [x, x, x, x, x];
15 |
16 | for (let i = 0, j = 9; i <= j; i++, j--)
17 | // ^
18 | print("a[" + i + "][" + j + "]= " + a[i][j]);
19 |
20 | print([1, 2, 3][1]);
21 |
22 | print("done.");
23 | }
24 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00array4_push_pop.ts:
--------------------------------------------------------------------------------
1 | function testNumCollection(): void {
2 | let collXYZ: number[] = [];
3 | assert(collXYZ.push(42) == 1, "push count");
4 | assert(collXYZ.length == 1, "length");
5 | assert(collXYZ[0] == 42, "value");
6 |
7 | assert(collXYZ.pop() == 42, "pop value");
8 | assert(collXYZ.length == 0, "length after pop");
9 | }
10 |
11 | function main() {
12 | testNumCollection();
13 | print("done.");
14 | }
15 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00array5_deconst.ts:
--------------------------------------------------------------------------------
1 | function main() {
2 | let [a, b] = [1, 2];
3 |
4 | print(a, b);
5 |
6 | [a, b] = [3, 4];
7 |
8 | print(a, b);
9 |
10 | t();
11 | t2();
12 |
13 | print("done.");
14 | }
15 |
16 | function t() {
17 | let a = 1;
18 | let b = 3;
19 |
20 | [a, b] = [b, a];
21 | print(a); // 3
22 | print(b); // 1
23 |
24 | assert(a == 3);
25 | assert(b == 1);
26 | }
27 |
28 | function f() {
29 | return [1, 2];
30 | }
31 |
32 | function t2() {
33 | let [a, b] = f();
34 | print(a); // 1
35 | print(b); // 2
36 |
37 | assert(a == 1);
38 | assert(b == 2);
39 | }
40 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00array7.ts:
--------------------------------------------------------------------------------
1 | // @strict-null false
2 | function foo3(results: number[] | undefined) {
3 | results ||= [];
4 | if (results) print("has values");
5 | let a = results;
6 | a.push(1);
7 | }
8 |
9 | function foo4(results: number[]) {
10 | results ??= [];
11 | if (results) print("has values");
12 | results.push(1);
13 | }
14 |
15 | function main()
16 | {
17 | foo3(undefined);
18 | foo4(null);
19 | print("done.");
20 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00array8_tuple_spread.ts:
--------------------------------------------------------------------------------
1 | function main() {
2 |
3 | let count = 0;
4 |
5 | [...[1, 2, "Hello"]].forEach(
6 | x => {
7 | if (typeof x == "string") { print(x); count++; }
8 | if (typeof x == "s32") { print(x); count++; }
9 | }
10 | );
11 |
12 | assert(count == 3);
13 |
14 | const v = [...([1, 2, 3, 4].filter(x => x % 2))];
15 | print( v.length );
16 |
17 | // it is array result is correct, if it is tuple result will not be correct
18 | assert (v.length == 2);
19 |
20 | print("done.");
21 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00array_cond_access.ts:
--------------------------------------------------------------------------------
1 | // @strict-null false
2 |
3 | type Array = T[];
4 |
5 | function getArray() : Array
6 | {
7 | return null;
8 | }
9 |
10 | function main()
11 | {
12 | const m = getArray();
13 | m! && m[0];
14 | m?.[0]! && m[0];
15 |
16 | assert(!m);
17 | assert(m === null);
18 |
19 | let arr2 : number[] | undefined;
20 |
21 | let r = arr2?.[10];
22 |
23 | assert (typeof r == "undefined");
24 |
25 | print("done.");
26 | }
27 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00array_of.ts:
--------------------------------------------------------------------------------
1 | namespace Array {
2 | function of(...arg: T[]) {
3 | return arg;
4 | }
5 | }
6 |
7 | function main() {
8 | const arr = Array.of('foo', 2, 'bar', true);
9 |
10 | for (const a of arr) {
11 | print("item :");
12 | if (typeof a == "string") {
13 | print("str:", a);
14 | }
15 | if (typeof a == "number") {
16 | print("str:", a);
17 | assert(a == 2);
18 | }
19 | if (typeof a == "boolean") {
20 | print("bool:", a);
21 | assert(a);
22 | }
23 | }
24 |
25 | print("done.");
26 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00array_view.ts:
--------------------------------------------------------------------------------
1 | let arr = []
2 |
3 | arr = [1, 2, 3, 4, 5];
4 |
5 | const arr2 = arr.view(1, 3);
6 | print(arr2.length, arr2[0], arr2[1], arr2[2]);
7 |
8 | assert(arr2.length === 3);
9 | assert(arr2[0] === 2);
10 | assert(arr2[2] === 4);
11 |
12 | print("done.");
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00arrow_generic.ts:
--------------------------------------------------------------------------------
1 | function test0() {
2 | const equal = (lhs: T, rhs: T): boolean {
3 | return lhs === rhs;
4 | };
5 | }
6 |
7 | function test1() {
8 | const equal = (lhs: T, rhs: T): boolean {
9 | return lhs === rhs;
10 | };
11 |
12 | print(equal(1, 2));
13 |
14 | print(equal("asd", "asd"));
15 | }
16 |
17 | function test2() {
18 | let r = 1;
19 |
20 | const equal = (lhs: T, rhs: R): boolean {
21 | print(r);
22 | return lhs === rhs;
23 | };
24 |
25 | print(equal(1, "asd"));
26 |
27 | print(equal("asd", "asd"));
28 | }
29 |
30 | function main() {
31 | test1();
32 | test2();
33 | print("done.");
34 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00arrow_global.ts:
--------------------------------------------------------------------------------
1 | const say = (speach: string) => print(speach);
2 | const sayT = (speach: T) => print(speach);
3 |
4 | function main() {
5 |
6 | say("Hello");
7 | sayT("Hello");
8 |
9 | print("done.");
10 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00arrow_in_arrow.ts:
--------------------------------------------------------------------------------
1 | function main() {
2 |
3 | const arrrr = () => (m: number) => () => (n: number) => m + n;
4 | const e = arrrr()(3)()(4);
5 |
6 | print(e);
7 |
8 | assert(e == 7);
9 |
10 | print("done.");
11 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00as_const.ts:
--------------------------------------------------------------------------------
1 | function main() {
2 |
3 | const const_obj = {
4 | val1: "Hello"
5 | };
6 |
7 | print("val1: ", const_obj.val1);
8 |
9 | let obj = const_obj;
10 |
11 | obj.val1 = "new val 1";
12 |
13 | print("val1: ", obj.val1);
14 |
15 | print("val1 as const: ", (obj as const).val1);
16 |
17 | // TODO: the following code will error
18 | //(obj as const).val1 = "new val 2";
19 |
20 | print("val1 as const: ", (obj as const).val1);
21 |
22 | print("done.");
23 | }
24 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00assert.ts:
--------------------------------------------------------------------------------
1 | function main() {
2 | assert(f1(), "assert failed.");
3 | print("done.");
4 | }
5 |
6 | function f1(): boolean {
7 | return true;
8 | }
9 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00async_await.ts:
--------------------------------------------------------------------------------
1 | async function f(a = 1) {
2 | return a;
3 | }
4 |
5 | function main() {
6 | const v = await f(2);
7 | print(v);
8 | assert(v == 2);
9 |
10 | const b = async () => 1;
11 | const r = await b();
12 | assert(r == 1);
13 |
14 | print("done.");
15 | }
16 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00class.ts:
--------------------------------------------------------------------------------
1 | // @strict-null false
2 | class Testrec {
3 | str: string;
4 | num: number;
5 | bool: boolean;
6 | str2: string;
7 | }
8 |
9 | function testRec0(): Testrec {
10 | let testrec = new Testrec();
11 | testrec.str2 = "Hello" + " world";
12 | testrec.str = testrec.str2;
13 | testrec.num = 42;
14 | assert(testrec.str == "Hello world", "recstr");
15 | assert(testrec.num == 42, "recnum");
16 | print(testrec.str2);
17 | let testrec2 = null;
18 | assert(testrec2 == null, "isinv");
19 | assert(testrec == testrec, "eq");
20 | assert(testrec != null, "non inv");
21 | return testrec;
22 | }
23 |
24 | function main(): void {
25 | let item = testRec0();
26 | print("done.");
27 | }
28 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00class_accessor2.ts:
--------------------------------------------------------------------------------
1 | class Person {
2 | static accessor sname: string;
3 | accessor name = "no value";
4 | constructor(name: string) {
5 | this.name = name;
6 | }
7 | }
8 |
9 | function main()
10 | {
11 | const p = new Person("hello");
12 | print(p.name);
13 | p.name = "hello2";
14 | print(p.name);
15 |
16 | Person.sname = "sname1";
17 |
18 | print(Person.sname);
19 |
20 | print("done.");
21 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00class_constr_fields.ts:
--------------------------------------------------------------------------------
1 | class Cls1
2 | {
3 | public v = 10;
4 | }
5 |
6 | class t
7 | {
8 | constructor(public a = new Cls1()) {}
9 | }
10 |
11 | function main() {
12 | const ti = new t();
13 | assert(ti.a.v == 10);
14 | print ("done.");
15 | }
16 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00class_deconst.ts:
--------------------------------------------------------------------------------
1 | class C2 {
2 | x: string;
3 | y: string;
4 |
5 | constructor() {
6 | let self = this; // ok
7 | let { x, y: y1 } = this; // ok
8 | ({ x, y: y1, "y": y1 } = this); // ok
9 | }
10 | }
11 |
12 | function main()
13 | {
14 | print("done.");
15 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00class_def_constr.ts:
--------------------------------------------------------------------------------
1 | class Point {
2 | x = 0;
3 | y = 0;
4 | }
5 |
6 | class PointX {
7 | x = 1;
8 | }
9 |
10 | class PointY extends PointX {
11 | y = 2;
12 | }
13 |
14 | function main() {
15 | const pt = new Point();
16 | // Prints 0, 0
17 | print(`${pt.x}, ${pt.y}`);
18 |
19 | const pt2 = new PointY();
20 | // Prints 0, 0
21 | print(`${pt2.x}, ${pt2.y}`);
22 |
23 | print("done.");
24 | }
25 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00class_discover_types.ts:
--------------------------------------------------------------------------------
1 | class c1 {
2 | pin: number;
3 |
4 | constructor(pin: number) {
5 | this.pin = pin;
6 | }
7 |
8 | hello() {
9 | return this.#hello();
10 | }
11 |
12 | #hello() {
13 | return this.pin;
14 | }
15 | }
16 |
17 | function main() {
18 | const c = new c1(2);
19 | print("Hello World", c.hello());
20 | assert(c.hello() == 2);
21 | delete c;
22 |
23 | print("done.");
24 | }
25 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00class_expression.ts:
--------------------------------------------------------------------------------
1 | function foo(x = class { static prop: string }): string {
2 | return x.prop;
3 | }
4 |
5 | function foo2(x = class { static prop: string; static func(); }) {
6 | x.func();
7 | }
8 |
9 | function main() {
10 | assert(foo(class { static prop = "hello" }).length == 5);
11 |
12 | foo2(class {
13 | static prop = "asdasd";
14 | static func() {
15 | print("Hello World 2", this.prop);
16 | }
17 | });
18 |
19 | main2();
20 |
21 | print("done.");
22 | }
23 |
24 | function main2() {
25 | const a = class { static prop = "hello" };
26 |
27 | function f(p: typeof a) {
28 | print(p.prop);
29 | }
30 |
31 | f(a);
32 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00class_expression2.ts:
--------------------------------------------------------------------------------
1 | function getClass() {
2 | let Point = class {
3 | constructor(public x: number, public y: number) { }
4 | public length() {
5 | return (this.x * this.x + this.y * this.y);
6 | }
7 | };
8 |
9 | return Point;
10 | }
11 |
12 | function main() {
13 | const PointClass = getClass();
14 | const p = new PointClass(3, 4); // p has anonymous class type
15 | print(p.length());
16 |
17 | assert(p.length() == 25);
18 |
19 | print("done.");
20 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00class_expression3.ts:
--------------------------------------------------------------------------------
1 | let Point = class {
2 | constructor(public x: number, public y: number) { }
3 | public length() {
4 | return (this.x * this.x + this.y * this.y);
5 | }
6 | };
7 |
8 | function main() {
9 | const p = new Point(3, 4); // p has anonymous class type
10 | print(p.length());
11 | print("done.");
12 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00class_from_tuple.ts:
--------------------------------------------------------------------------------
1 | class Point {
2 | x: number;
3 | y: number;
4 | }
5 |
6 | class Line {
7 | constructor(public start: Point, public end: Point) { }
8 | }
9 |
10 | const l = new Line({ x: 0, y: 1 }, { x: 1.0, y: 2.0 });
11 |
12 | print (l.start.x, l.start.y, l.end.x, l.end.y);
13 |
14 | assert(l.start.x == 0 && l.start.y == 1 && l.end.x == 1.0 && l.end.y == 2.0);
15 |
16 | {
17 | class Point {
18 | x: T;
19 | y: T;
20 | }
21 |
22 | class Line {
23 | constructor(public start: Point, public end: Point) { }
24 | }
25 |
26 | const l = new Line({ x: 0, y: 1 }, { x: 1.0, y: 2.6 });
27 |
28 | print (l.start.x, l.start.y, l.end.x, l.end.y);
29 |
30 | assert(l.start.x == 0 && l.start.y == 1 && l.end.x == 1.0 && l.end.y == 2.6);
31 | }
32 |
33 | print("done.");
34 |
35 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00class_generic.ts:
--------------------------------------------------------------------------------
1 | class B
2 | {
3 | foo(x: T) {
4 | assert(x == 1);
5 | }
6 | }
7 |
8 | //class A extends B { }
9 |
10 | function main() {
11 | let x = new B();
12 | //let x: A = new A();
13 | x.foo(1); // no error
14 |
15 | print("done.");
16 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00class_generic_iface.ts:
--------------------------------------------------------------------------------
1 | interface IList {
2 | data(): T;
3 | next(): string;
4 | }
5 |
6 | class List implements IList {
7 | data(): U { return 1; }
8 | next(): string { return "Hello"; };
9 | }
10 |
11 | function main() {
12 | const l = new List();
13 | assert(l.data() == 1);
14 | const i = >l;
15 | assert(i.data() == 1);
16 | print("done.");
17 | }
18 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00class_generic_method.ts:
--------------------------------------------------------------------------------
1 | class Lib {
2 | max(a: T, b: T): T {
3 | return a > b ? a : b;
4 | }
5 | }
6 |
7 | function main() {
8 | const c = new Lib();
9 | assert(c.max(10, 20) == 20);
10 | assert(c.max("a", "b") == "b");
11 | assert(c.max(10, 20) == 20);
12 |
13 | print("done.");
14 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00class_generic_method2.ts:
--------------------------------------------------------------------------------
1 | class S {
2 |
3 | test(t: T) {
4 | if (t > 0) return 11;
5 | return 1;
6 | }
7 |
8 | }
9 |
10 | function main() {
11 |
12 | const s = new S();
13 |
14 | const r = s.test(10);
15 | print(r);
16 | assert(r == 11);
17 |
18 | print("done.");
19 | }
20 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00class_iface.ts:
--------------------------------------------------------------------------------
1 | class S {
2 | val = 5;
3 |
4 | print() {
5 | print("Hello", this.val);
6 | assert(this.val == 5);
7 | }
8 | }
9 |
10 | interface IFace2 {
11 | print();
12 | }
13 |
14 | function main() {
15 | const s = new S();
16 | const iface2: IFace2 = s;
17 | iface2.print();
18 |
19 | const m = iface2.print;
20 | m();
21 |
22 | const mt: () => void = iface2.print;
23 | mt();
24 |
25 | print("done.");
26 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00class_indexer.ts:
--------------------------------------------------------------------------------
1 | class Test {
2 |
3 | #val: string;
4 |
5 | // to be able to assign get/set to xxx[number]
6 | [index1: number]: string;
7 |
8 | get(index: number): string {
9 | return this.#val;
10 | }
11 |
12 | set(index: number, value: string) {
13 | // nothing todo
14 | this.#val = value;
15 | }
16 | }
17 |
18 | const t = new Test();
19 |
20 | t[10] = "hello";
21 |
22 | assert(t[10] = "hello");
23 |
24 | print(t[10]);
25 |
26 | {
27 | print("done.");
28 | }
29 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00class_iterator.ts:
--------------------------------------------------------------------------------
1 | let glb1 = 0;
2 |
3 | class C {
4 | v = 10;
5 | *iter() {
6 | for (let i = 0; i < 10; i++) yield this.v + i;
7 | }
8 | }
9 |
10 | function main() {
11 | for (const v of new C().iter()) { glb1++; print(v) };
12 | assert(glb1 == 10);
13 | print("done.");
14 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00class_iterator_super.ts:
--------------------------------------------------------------------------------
1 | class B9 {
2 | g() {}
3 | }
4 |
5 | class C9 extends B9 {
6 | async * f() {
7 | super.g();
8 | }
9 | }
10 |
11 | print("done.");
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00class_local_decl.ts:
--------------------------------------------------------------------------------
1 | function getPointFactory(x: number, y: number) {
2 | class P {
3 | x = 0;
4 | y = 0;
5 | }
6 |
7 | return new P();
8 | }
9 |
10 | function main() {
11 | const PointZero = getPointFactory(0, 0);
12 | const PointOne = getPointFactory(1, 1);
13 | print("done.");
14 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00class_nested.ts:
--------------------------------------------------------------------------------
1 | function f3() {
2 | function f(x: X, y: Y) {
3 | class C {
4 | constructor(public x: X, public y: Y) {
5 | }
6 | }
7 | return new C(x, y);
8 | }
9 |
10 | let c = f(10, "hello");
11 | let x = c.x; // number
12 | let y = c.y; // string
13 |
14 | print(x, y);
15 |
16 | let c2 = f("hello2", 20);
17 | let x2 = c2.x; // number
18 | let y2 = c2.y; // string
19 |
20 | print(x2, y2);
21 | }
22 |
23 | function main() {
24 | f3();
25 | print("done.");
26 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00class_or_interface_to_tuple.ts:
--------------------------------------------------------------------------------
1 | class S {
2 | a = 30.0;
3 | b = "ddd";
4 | r = true;
5 | }
6 |
7 | interface IS {
8 | a: number;
9 | b: string;
10 | r: boolean;
11 | }
12 |
13 | function main() {
14 | let o = { a: 10, b: "asd" };
15 |
16 | assert(o.a == 10)
17 | assert(o.b == "asd")
18 |
19 | o = { s: "xxx", a: 20, b: "sss", c: "ddd" };
20 |
21 | assert(o.a == 20)
22 | assert(o.b == "sss")
23 |
24 | o = new S();
25 |
26 | print(o.a, o.b);
27 |
28 | assert(o.a == 30)
29 | assert(o.b == "ddd")
30 |
31 | o = new S();
32 |
33 | print(o.a, o.b);
34 |
35 | assert(o.a == 30)
36 | assert(o.b == "ddd")
37 |
38 | print("done.");
39 | }
40 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00class_protected_constr.ts:
--------------------------------------------------------------------------------
1 | class Cls1
2 | {
3 | test: int;
4 |
5 | protected constructor()
6 | {
7 | print("protected ctor");
8 | this.test = 111;
9 | }
10 |
11 | public static getCls1()
12 | {
13 | return new Cls1();
14 | }
15 | }
16 |
17 | //const cls0 = new Cls1();
18 | //print(cls0.test); // error
19 |
20 | const cls1 = Cls1.getCls1();
21 | print(cls1.test);
22 | assert(cls1.test == 111);
23 |
24 | print("done.");
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00class_recursive.ts:
--------------------------------------------------------------------------------
1 | class Node {
2 | v: T;
3 | k: string;
4 | next: Node;
5 | }
6 |
7 | function main() {
8 | let n = new Node()
9 | n.next = n
10 | n.k = "Hello";
11 | n.v = 10.0;
12 |
13 | let s = new Node()
14 | s.next = s
15 | s.k = "Hello";
16 | s.v = "rrr";
17 |
18 | print("done.");
19 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00class_stack.ts:
--------------------------------------------------------------------------------
1 | // TODO: add @novtable or @novirtualtable to control generation of virtual elements
2 | class Animal {
3 | move(distanceInMeters = 0) {
4 | print(`Animal moved ${distanceInMeters}m.`);
5 | }
6 | }
7 |
8 | function main() {
9 | const dog = new Animal();
10 | dog.move(10);
11 |
12 | // TODO: ERROR can't create class with vtable on stack
13 | // const dog2 = Animal();
14 | // dog2.move(11);
15 |
16 | print("done.");
17 | }
18 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00class_static_block.ts:
--------------------------------------------------------------------------------
1 | class C {
2 | static x: number;
3 | static {
4 | C.x = 1;
5 | }
6 | }
7 |
8 | function main() {
9 | print(C.x);
10 | assert(C.x == 1);
11 | print("done.");
12 | }
13 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00class_static_constr.ts:
--------------------------------------------------------------------------------
1 | let glb1 = 0;
2 |
3 | class Color {
4 | static constructor() {
5 | glb1++;
6 | print("Static construct");
7 | }
8 |
9 | constructor(public r: number,
10 | public g: number,
11 | public b: number) {
12 | }
13 |
14 | static white = 1;
15 | }
16 |
17 | class Color2 {
18 | static constructor() {
19 | glb1++;
20 | print("Static construct 2");
21 | }
22 | }
23 |
24 | class Color3 {
25 | constructor(public r: number,
26 | public g: number,
27 | public b: number) {
28 | }
29 |
30 | static white = 1 + 1;
31 | }
32 |
33 |
34 | function main() {
35 | assert(glb1 == 2);
36 | assert(Color3.white == 2);
37 | print("done.");
38 | }
39 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00class_static_generic_method.ts:
--------------------------------------------------------------------------------
1 | class Lib {
2 | static max(a: T, b: T): T {
3 | return a > b ? a : b;
4 | }
5 | }
6 |
7 | function main() {
8 | assert(Lib.max(10, 20) == 20);
9 | assert(Lib.max("a", "b") == "b");
10 | assert(Lib.max(20, 30) == 30);
11 | print("done.");
12 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00class_static_generic_method2.ts:
--------------------------------------------------------------------------------
1 | class S {
2 | static test(this: S, t: T) {
3 | if (t > 0) return 10;
4 | return 1;
5 | }
6 |
7 | static test2(t: T) {
8 | if (t > 0) return 11;
9 | return 1;
10 | }
11 |
12 | }
13 |
14 | function main() {
15 |
16 | const s = new S();
17 |
18 | const r = s.test(10);
19 | print(r);
20 | assert(r == 10);
21 |
22 | const r2 = s.test2(10);
23 | print(r2);
24 |
25 | assert(r2 == 11);
26 | print("done.");
27 | }
28 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00class_static_generic_method3.ts:
--------------------------------------------------------------------------------
1 | class CustomDate {
2 | static parse(dateString) {
3 | return this.createDate(1, 2, 3);
4 | }
5 |
6 | // Helper function to create a Date object using UTC time
7 | static createDate(year, month, day, hour = 0, minute = 0, second = 0) {
8 | return year + month;
9 | }
10 | }
11 |
12 | CustomDate.parse("test");
13 |
14 | print("done.");
15 |
16 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00class_super_static.ts:
--------------------------------------------------------------------------------
1 | class SomeBase {
2 | public static publicStaticMember = 0;
3 | }
4 |
5 | class SomeDerived3 extends SomeBase {
6 | static fn() {
7 | super.publicStaticMember = 3;
8 | }
9 | static get a() {
10 | return '';
11 | }
12 | static set a(n) {
13 | }
14 | }
15 |
16 | function main() {
17 |
18 | SomeDerived3.fn();
19 | assert(SomeBase.publicStaticMember == 3);
20 |
21 | print("done.");
22 | }
23 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00class_symbol_iterator.ts:
--------------------------------------------------------------------------------
1 | class StringIterator {
2 | next() {
3 | print("next...");
4 |
5 | return {
6 | done: true,
7 | value: ""
8 | };
9 | }
10 | [Symbol.iterator]() {
11 | // TODO: finish it, should be called
12 | print("iterator...");
13 | return this;
14 | }
15 | }
16 |
17 | function main() {
18 | for (const v of new StringIterator) { }
19 |
20 | print("done.");
21 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00class_var_args.ts:
--------------------------------------------------------------------------------
1 | let a: string[];
2 |
3 | class C1 {
4 | constructor() {
5 | }
6 |
7 | foo(x: number, y: number, ...z: string[]) {
8 | }
9 | }
10 |
11 | class D1 extends C1 {
12 | constructor() {
13 | super();
14 | }
15 | foo() {
16 | super.foo(1, 2, ...a);
17 | }
18 | }
19 |
20 | class C2 {
21 | constructor(x: number, y: number, ...z: string[]) {
22 | this.foo(x, y);
23 | this.foo(x, y, ...z);
24 | }
25 | foo(x: number, y: number, ...z: string[]) {
26 | }
27 | }
28 |
29 | class D2 extends C2 {
30 | constructor() {
31 | super(1, 2);
32 | super(1, 2, ...a);
33 | }
34 | foo() {
35 | super.foo(1, 2);
36 | super.foo(1, 2, ...a);
37 | }
38 | }
39 |
40 | function main() {
41 | print("done.");
42 | }
43 |
44 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00class_virtual_call.ts:
--------------------------------------------------------------------------------
1 | let a_method3 = 0;
2 | let c_method3 = 0;
3 |
4 | class A
5 | {
6 | method3()
7 | {
8 | a_method3++;
9 | print("A::method - 3");
10 | }
11 | }
12 |
13 | class B extends A
14 | {
15 | method()
16 | {
17 | this.method3();
18 | super.method3();
19 | }
20 | }
21 |
22 | class C extends B
23 | {
24 | method3()
25 | {
26 | c_method3++;
27 | print("C::method - 3");
28 | super.method3();
29 | }
30 | }
31 |
32 | function main()
33 | {
34 | const c = new C();
35 | c.method();
36 |
37 | print(a_method3);
38 | print(c_method3);
39 |
40 | assert(a_method3 == 2);
41 | assert(c_method3 == 1);
42 |
43 | print("done.");
44 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00class_virtual_table.ts:
--------------------------------------------------------------------------------
1 | function isFinite(val: number): boolean {
2 | return val != Number.POSITIVE_INFINITY && val != Number.NEGATIVE_INFINITY;
3 | }
4 |
5 | class Number {
6 | public static NEGATIVE_INFINITY = -1.0 / 0.0;
7 |
8 | public static POSITIVE_INFINITY = 1.0 / 0.0;
9 |
10 | constructor(private value: number) {
11 | }
12 |
13 | public isFinite(): boolean {
14 | return isFinite(this.value);
15 | }
16 |
17 | public valueOf() {
18 | return this.value;
19 | }
20 | }
21 |
22 | function main()
23 | {
24 | const a = new Number(20);
25 | assert(a.valueOf() == 20.0);
26 | print("done.");
27 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00computedpropertyname.ts:
--------------------------------------------------------------------------------
1 | const c = "c";
2 | const d = 10;
3 | // TODO:
4 | //const e = Symbol();
5 |
6 | const enum E1 {
7 | A,
8 | B,
9 | C,
10 | }
11 |
12 | const enum E2 {
13 | A = "A",
14 | B = "B",
15 | C = "C",
16 | }
17 |
18 | type Foo = {
19 | a: string; // String-like name
20 | 5: string; // Number-like name
21 | // TODO:
22 | //[c]: string; // String-like name
23 | // TODO:
24 | //[d]: string; // Number-like name
25 | // TODO:
26 | //[e]: string; // Symbol-like name
27 | [E1.A]: string; // Number-like name
28 | [E2.A]: string; // String-like name
29 | };
30 |
31 | type K1 = keyof Foo; // "a" | 5 | "c" | 10 | typeof e | E1.A | E2.A
32 | type K2 = Extract; // "a" | "c" | E2.A
33 | type K3 = Extract; // 5 | 10 | E1.A
34 | type K4 = Extract; // typeof e
35 |
36 | function main()
37 | {
38 | print("done.");
39 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00cond_expr.ts:
--------------------------------------------------------------------------------
1 | function main() {
2 | let a = 0, b = 1;
3 | print(b > 0 ? b : 2);
4 | print(b < 0 ? b : 2);
5 | print(b ? b : 2);
6 | print(!b ? b : 2);
7 |
8 | print("done.");
9 | }
10 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00decorators.ts:
--------------------------------------------------------------------------------
1 | @used
2 | let a = 10;
3 |
4 | @noinline
5 | @optnone
6 | @used
7 | function test1() {
8 | print("Hello 1");
9 | }
10 |
11 | function test2() {
12 | print("Hello 2");
13 | }
14 |
15 | function main() {
16 |
17 | test1();
18 | test1();
19 |
20 | test2();
21 | test2();
22 |
23 | print("done.");
24 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00dowhile.ts:
--------------------------------------------------------------------------------
1 | function main() {
2 | assert(test() == 0, "failed. 1");
3 |
4 | print("done.");
5 | }
6 |
7 | function test() {
8 | let i = 10;
9 | do {
10 | print(i);
11 | } while (--i > 0);
12 |
13 | return i;
14 | }
15 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00every.ts:
--------------------------------------------------------------------------------
1 | function main()
2 | {
3 | const foo: (number | string)[] = ['aaa'];
4 |
5 | //const isString = (x: unknown): x is string => typeof x === 'string';
6 | const isString = (x: T): x is string => typeof x === 'string';
7 |
8 | if (foo.every(isString)) {
9 | print("all strings");
10 | }
11 | else
12 | {
13 | assert(false);
14 | }
15 |
16 | print("done.");
17 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00extends.ts:
--------------------------------------------------------------------------------
1 | function assign(target: T, source: U): T {
2 | return target;
3 | }
4 |
5 | function main()
6 | {
7 | let x = { a: 1, b: 2, c: 3, d: 4 };
8 | assign(x, { b: 10, d: 20 });
9 | //assign(x, { e: 0 }); // Error
10 |
11 | print("done.");
12 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00extension_cond_access.ts:
--------------------------------------------------------------------------------
1 | // @strict-null false
2 | let glb1 = 0;
3 | function test(this: string) {
4 | print(this);
5 | glb1++;
6 | }
7 |
8 | function main() {
9 | let s: string = "asd";
10 | s?.test();
11 |
12 | s = null;
13 | s?.test();
14 |
15 | assert(glb1 == 1);
16 |
17 | // ref to method
18 | const m = "asd-m"?.test;
19 | m();
20 |
21 | let m2: () => void;
22 | m2 = m;
23 | m2();
24 |
25 | const test = (names: string[]) => names?.filter(x => x);
26 | for (const s of test(["asd", "asd1", null])) print(s);
27 |
28 | print("done.");
29 | }
30 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00filter.ts:
--------------------------------------------------------------------------------
1 | function main() {
2 | const arr = [1, 2, 3, 4, 5];
3 |
4 | let count = 0;
5 | for (const v of arr.filter(x => x % 2)) {
6 | print(v);
7 | count++;
8 | }
9 |
10 | assert(count == 3);
11 |
12 | print("done.");
13 | }
14 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00for.ts:
--------------------------------------------------------------------------------
1 | function main() {
2 | assert(test1() == 9, "failed. 1");
3 | assert(test2() == 10, "failed. 2");
4 |
5 | print("done.");
6 | }
7 |
8 | function test1() {
9 | let j = 0;
10 | for (let i = 0; i < 10; i++) {
11 | print(i);
12 | j = i;
13 | }
14 |
15 | return j;
16 | }
17 |
18 | function test2() {
19 | let j = 0;
20 | for (let i = 0; i++ < 10; ) {
21 | print(i);
22 | j = i;
23 | }
24 |
25 | return j;
26 | }
27 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00for_await.ts:
--------------------------------------------------------------------------------
1 | function main1() {
2 | for await (const v of [1, 2, 3, 4, 5]) {
3 | print(v);
4 | }
5 | }
6 |
7 | function main2() {
8 | let count = 0;
9 | for await (const v of [1, 2, 3, 4, 5]) {
10 | print(v);
11 | assert(v >= 1 && v <= 5);
12 | count++;
13 | }
14 |
15 | assert(count == 5);
16 | }
17 |
18 | function main() {
19 | main1();
20 | main2();
21 |
22 | print("done.");
23 | }
24 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00for_await_yield.ts:
--------------------------------------------------------------------------------
1 | async function sleep(d: number)
2 | {
3 | print("sleep", d);
4 | }
5 |
6 | async function* g() {
7 | yield 1;
8 | await sleep(100);
9 | yield* [2, 3];
10 | yield* (async function*() {
11 | await sleep(100);
12 | yield 4;
13 | })();
14 | }
15 |
16 | async function f() {
17 | for await (const x of g()) {
18 | print(x);
19 | }
20 | }
21 |
22 | function main() {
23 |
24 | await f();
25 | (async function () { await f(); })();
26 |
27 | print("done.");
28 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00for_in.ts:
--------------------------------------------------------------------------------
1 | function main() {
2 | /*
3 | const object : { name: string, age: number } = { name: "foo", age: 10.0 };
4 |
5 | for (const property in object) {
6 | print(`${property}: ${object[property]}`);
7 | }
8 | */
9 |
10 | const object = [10, 20, 30];
11 |
12 | for (const property in object) {
13 | print(`${property}: ${object[property]}`);
14 | }
15 |
16 | print("done.");
17 | }
18 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00for_of.ts:
--------------------------------------------------------------------------------
1 | type int = TypeOf<1>;
2 |
3 | function f(a: [int, string][]) {
4 | for (const [k, v] of a) {
5 | print(k, v);
6 | }
7 | }
8 |
9 | function main() {
10 | for (const q of [1, 12]) {
11 | print(q);
12 | }
13 |
14 | for (const l of "Hello") {
15 | print(l);
16 | }
17 |
18 | const array1 = ["a", "b", "c"];
19 |
20 | for (const element of array1) {
21 | print(element);
22 | }
23 |
24 | const trees = [
25 | [1, "redwood"],
26 | [2, "bay"],
27 | [3, "cedar"],
28 | [4, "oak"],
29 | [5, "maple"],
30 | ];
31 |
32 | for (const [k, v] of trees) {
33 | print(k, v);
34 | }
35 |
36 | f(trees);
37 |
38 | print("done.");
39 | }
40 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00funcs_expression_generic.ts:
--------------------------------------------------------------------------------
1 | function test1() {
2 | const equal = function (lhs: T, rhs: T): boolean {
3 | return lhs === rhs;
4 | };
5 |
6 | print(equal(1, 2));
7 |
8 | print(equal("asd", "asd"));
9 | }
10 |
11 | function test2() {
12 | let r = 1;
13 |
14 | const equal = function(lhs: T, rhs: R): boolean {
15 | print(r);
16 | return lhs === rhs;
17 | };
18 |
19 | print(equal(1, "asd"));
20 |
21 | print(equal("asd", "asd"));
22 | }
23 |
24 | function main() {
25 | test1();
26 | test2();
27 | print("done.");
28 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00funcs_expression_iterator.ts:
--------------------------------------------------------------------------------
1 | let glb1 = 0;
2 |
3 | function* iter(this: string) {
4 | for (const c of this)
5 | yield c;
6 | }
7 |
8 | function main() {
9 |
10 | for (const a of "asd".iter()) { glb1++; print(a); };
11 |
12 | assert(glb1 == 3);
13 |
14 | print("done.");
15 | }
16 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00funcs_generic.ts:
--------------------------------------------------------------------------------
1 | function test(t: T) {
2 | return t;
3 | }
4 |
5 | function fib(n: T) {
6 | return n <= 2 ? n : fib(n - 1) + fib(n - 2);
7 | }
8 |
9 | function toString(this: T)
10 | {
11 | return `${this}`;
12 | }
13 |
14 | function main() {
15 | print(test(11), test("Hello1"));
16 |
17 | assert(test(10) == 10);
18 | assert(test("Hello") == "Hello");
19 |
20 | assert(fib(5) == 8);
21 |
22 | print("done.");
23 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00funcs_generic_arrow.ts:
--------------------------------------------------------------------------------
1 | function some(arr: T[], f: (it: T) => boolean)
2 | {
3 | for (const v of arr) if (f(v)) return true;
4 | return false;
5 | }
6 |
7 | function map(a: T[], f:(i: T) => R)
8 | {
9 | let r = 0;
10 | for (const v of a) r += f(v);
11 | print(r);
12 | assert(r == 9);
13 | }
14 |
15 | function reduce(arr: T[], f: (s: R, v: T) => R, init: R)
16 | {
17 | let r = init;
18 | for (const v of arr) r = f(r, v);
19 | return r;
20 | }
21 |
22 | function main() {
23 | let str = [1, 2, 3];
24 | assert(some(str, (x => x == 2)), "sometrue");
25 | assert(!some(str, (x => x < 0)), "somefalse");
26 |
27 | map(str, i => i + 1);
28 |
29 | let count = 0;
30 | map([1, 2, 3], (i) => { count++; return i + 1; });
31 | assert(count == 3);
32 |
33 | let sum = reduce([1, 2, 3], (s, v) => s + v, 0);
34 | assert(sum == 6, "red")
35 |
36 | print("done.");
37 | }
38 |
39 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00funcs_generic_iterator.ts:
--------------------------------------------------------------------------------
1 | function* map(a: T[], f: (i: T) => R) {
2 | for (const v of a) yield f(v);
3 | }
4 |
5 | function main() {
6 | let count = 0;
7 | for (const v of map([1, 2, 3], (i) => { count++; return i + 1; })) {
8 | print(v);
9 | }
10 |
11 | assert(count == 3);
12 | print("done.");
13 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00funcs_generic_with_typeof.ts:
--------------------------------------------------------------------------------
1 | // @strict-null false
2 | function gen(t: T)
3 | {
4 | if (typeof t == "string")
5 | {
6 | return t;
7 | }
8 |
9 | return "no";
10 | }
11 |
12 | const v1 = gen("test");
13 | assert(v1 == "test")
14 | print(v1);
15 |
16 | const v2 = gen(null);
17 | assert(v2 == "no")
18 | print(v2);
19 |
20 | const v3 = gen();
21 | assert(v3 == "no")
22 | print(v3);
23 |
24 | print("done.");
25 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00funcs_nesting.ts:
--------------------------------------------------------------------------------
1 | namespace s {
2 | function f1() {
3 | function clear() {
4 | print("clear 1");
5 | return 1;
6 | }
7 |
8 | return clear();
9 | }
10 |
11 | function f2() {
12 | function clear() {
13 | print("clear 2");
14 | return 2;
15 | }
16 |
17 | return clear();
18 | }
19 | }
20 |
21 | function main() {
22 | assert(s.f1() == 1);
23 | assert(s.f2() == 2);
24 | print("done.")
25 | }
26 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00funcs_nesting_capture.ts:
--------------------------------------------------------------------------------
1 | function render(screenWidth, screenHeight) {
2 | const getPoint = (x, y) => {
3 | const recenterX = x1 => (x1 - (screenWidth / 2.0)) / 2.0 / screenWidth;
4 | const recenterY = y1 => -(y1 - (screenHeight / 2.0)) / 2.0 / screenHeight;
5 | return recenterX(x) + recenterY(y);
6 | }
7 |
8 | const v = getPoint(512, 384);
9 | print(v);
10 | assert(v === 0);
11 |
12 | const v2 = getPoint(1024, 768);
13 | print(v2);
14 | assert(v2 === 0);
15 |
16 | const v3 = getPoint(300, 200);
17 | print(v3);
18 | assert((v3 - 0.016276) < 0.0001);
19 |
20 | }
21 |
22 | render(1024, 768);
23 |
24 | print("done.");
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00funcs_nesting_generic.ts:
--------------------------------------------------------------------------------
1 | function f()
2 | {
3 | let a = 0;
4 | function test(v: T)
5 | {
6 | a = v;
7 | }
8 |
9 | test>(10);
10 | print(a);
11 | assert(a == 10);
12 | }
13 |
14 | function main()
15 | {
16 | f();
17 | print("done.");
18 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00funcs_typeless_function_as_generic.ts:
--------------------------------------------------------------------------------
1 | function getMax(a, b)
2 | {
3 | return a > b ? a : b;
4 | }
5 |
6 | function init(f: (x:int, y:int) => int) {
7 | assert(f(10, 20) == 20);
8 | }
9 |
10 | function main() {
11 |
12 | init(getMax); init(getMax);
13 |
14 | assert(getMax(1, 2) == 2);
15 | assert(getMax(1, 2) == 2);
16 | assert(getMax(2.1, 3.2) == 3.2);
17 | assert(getMax("200", "400") == "400");
18 |
19 | print("done.");
20 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00funcs_vararg.ts:
--------------------------------------------------------------------------------
1 | function fn5(x: string, ...y: any[]) {
2 | print("count: ", y.length);
3 | assert(y.length == 3);
4 | }
5 |
6 | function main() {
7 | fn5("hello", 1, 2, "str");
8 | print("done.");
9 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00generator5.ts:
--------------------------------------------------------------------------------
1 | let glb1 = 0;
2 |
3 | function* g() {
4 | yield* (function* () {
5 | yield 1;
6 | yield 2;
7 | yield 3;
8 | })();
9 | }
10 |
11 | function f() {
12 | for (const x of g()) {
13 | print(x);
14 | glb1++;
15 | }
16 | }
17 |
18 | function main() {
19 | f();
20 |
21 | assert(glb1 == 3);
22 |
23 | print("done.");
24 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00generator6.ts:
--------------------------------------------------------------------------------
1 | let glb1 = 0;
2 | let glb2 = 0;
3 |
4 | function* g() {
5 | yield* (function* () {
6 | yield 1.0;
7 | yield 2.0;
8 | yield "3.0";
9 | yield 4.0;
10 | })();
11 | }
12 |
13 | function main() {
14 | for (const x of g())
15 | if (typeof x == "string")
16 | print("string: ", x, glb1++);
17 | else if (typeof x == "number")
18 | print("number: ", x, glb2++);
19 |
20 | assert(glb1 == 1);
21 | assert(glb2 == 3);
22 |
23 | print("done.");
24 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00generic_arguments_name_conflict.ts:
--------------------------------------------------------------------------------
1 | type If = C extends true ? T : F;
2 |
3 | type And = If;
4 |
5 | type A1 = And; // false
6 |
7 | interface A
8 | {
9 | a: 'A';
10 | }
11 |
12 | function main()
13 | {
14 | print("done.");
15 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00globals.ts:
--------------------------------------------------------------------------------
1 | let glb1 = 1;
2 | const glb2 = 2;
3 |
4 | function main() {
5 | assert(glb1 == 1, "Failed. glb1");
6 | assert(glb2 == 2, "Failed. glb2");
7 | glb1 = glb1 + 1;
8 | assert(glb1 == 2, "Failed. glb1++");
9 |
10 | print("done.");
11 | }
12 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00globals2.ts:
--------------------------------------------------------------------------------
1 | function nested_global() {
2 | // example 1
3 | var a = 10;
4 |
5 | function f() {
6 | print("Hello func f", a);
7 | }
8 |
9 | f();
10 | }
11 |
12 | function main() {
13 | let j = 10;
14 | var i = j + 10;
15 |
16 | assert(i == 20, "Failed. global i");
17 |
18 | nested_global();
19 |
20 | print("done.");
21 | }
22 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00globals3.ts:
--------------------------------------------------------------------------------
1 | function main()
2 | {
3 | var a = 10;
4 |
5 | print(a);
6 |
7 | assert(a == 10);
8 |
9 | f();
10 |
11 | rrr.t();
12 |
13 | print("done.");
14 | }
15 |
16 | function f()
17 | {
18 | assert(a == 10);
19 |
20 | print(a);
21 |
22 | a = 20;
23 |
24 | assert(a == 20);
25 | }
26 |
27 | namespace rrr
28 | {
29 | var r = 30;
30 |
31 | function t()
32 | {
33 | print(r);
34 | print(a);
35 |
36 | assert(a == 20);
37 | assert(r == 30);
38 | }
39 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00if_conditional_compile.ts:
--------------------------------------------------------------------------------
1 | // @strict-null false
2 | function isArray(value: T): value is T {
3 | return true;
4 | }
5 |
6 | function gen(t: T)
7 | {
8 | if (isArray(t))
9 | {
10 | return t.length;
11 | }
12 |
13 | return "int";
14 | }
15 |
16 | const v1 = gen(23);
17 | print(v1);
18 | assert(v1 == "int");
19 |
20 | const v2 = gen(null);
21 | print(v2);
22 | assert(v2 == "0");
23 |
24 | print("done.");
25 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00if_return.ts:
--------------------------------------------------------------------------------
1 | function main() {
2 | assert(test(1) == 3, "failed. 1");
3 | test2(1);
4 | assert(test3(1) == 5, "failed. 3");
5 | assert(test4(1) == 3, "failed. 4");
6 |
7 | print("done.");
8 | }
9 |
10 | function test(a: number) {
11 | if (a == 1) {
12 | return 3;
13 | }
14 |
15 | return 2;
16 | }
17 |
18 | function test2(a: number) {
19 | if (a == 1) {
20 | return;
21 | }
22 |
23 | assert(false, "failed. 2");
24 | }
25 |
26 | function test3(a: number) {
27 | if (a == 1) {
28 | a = a + 1;
29 | a = a + 1;
30 | }
31 |
32 | a = a + 1;
33 | a = a + 1;
34 |
35 | return a;
36 | }
37 |
38 | function test4(a: number) {
39 | if (a == 1) {
40 | a = a + 1;
41 | a = a + 1;
42 | return a;
43 | }
44 |
45 | a = a + 1;
46 | a = a + 1;
47 |
48 | return a;
49 | }
50 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00in.ts:
--------------------------------------------------------------------------------
1 | function main() {
2 | // Arrays
3 | const trees = ["redwood", "bay", "cedar", "oak", "maple"];
4 |
5 | assert(!(-1 in trees));
6 | assert(0 in trees);
7 | assert(3 in trees);
8 | assert(!(5 in trees));
9 | assert(!(6 in trees));
10 |
11 | for (let i = 0; i in trees; i++) {
12 | print(trees[i]);
13 | }
14 |
15 | const obj = { test: 1 };
16 |
17 | assert("test" in obj);
18 | assert(!("test1" in obj));
19 |
20 | print("done.");
21 | }
22 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00infer.ts:
--------------------------------------------------------------------------------
1 | type Array = T[];
2 |
3 | type Flatten = Type extends Array ? Item : Type;
4 |
5 | type GetReturnType = Type extends (...args: never[]) => infer Return
6 | ? Return
7 | : never;
8 |
9 | type Num = GetReturnType<() => number>;
10 |
11 | type ToArrayNonDist = [Type] extends [unknown] ? Type[] : never;
12 |
13 | function isDefined(value: T | undefined | null): value is T {
14 | return value !== undefined && value !== null;
15 | }
16 |
17 |
18 | function main() {
19 | // 1
20 | let num1: Flatten = 20;
21 | let num2 = 30;
22 |
23 | print(num1!, num2);
24 |
25 | let arr: ToArrayNonDist = ["1", "2"];
26 |
27 | // 2
28 | const foo: string | undefined = "asd";
29 |
30 | if (isDefined(foo)) {
31 | print(foo);
32 | }
33 |
34 | print("done.");
35 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00instanceof.ts:
--------------------------------------------------------------------------------
1 | type str = TypeOf<"">;
2 |
3 | class Cls1 {
4 | foo(): number {
5 | print("Hello");
6 | return 1;
7 | }
8 | }
9 |
10 | class Cls2 extends Cls1 { }
11 |
12 | class C {
13 |
14 | foo() { }
15 |
16 | }
17 |
18 | class C2 extends C { }
19 |
20 | class D { }
21 |
22 | function iftrue(a: any) {
23 | assert(a instanceof C);
24 | }
25 |
26 | function iffalse(a: any) {
27 | assert(!(a instanceof C));
28 | }
29 |
30 | function main() {
31 | assert("asd" instanceof str);
32 |
33 | const cls1 = new Cls1();
34 | const cls2 = new Cls2();
35 |
36 | assert(cls1 instanceof Cls1);
37 | assert(!(cls1 instanceof Cls2));
38 | assert(cls2 instanceof Cls2);
39 | assert(cls2 instanceof Cls1);
40 |
41 | iffalse(1);
42 | iffalse("asd");
43 | iftrue(new C());
44 | iftrue(new C2());
45 | iffalse(new D());
46 |
47 | print("done.");
48 | }
49 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00interface.ts:
--------------------------------------------------------------------------------
1 | namespace Ifaces {
2 | interface IFoo {
3 | foo(): number;
4 | }
5 | }
6 |
7 | interface IFoo {
8 | foo(): number;
9 | foo2(): number;
10 | }
11 |
12 | class Cls1 implements Ifaces.IFoo, IFoo {
13 | foo(): number {
14 | print("Hello");
15 | return 1;
16 | }
17 |
18 | foo2(): number {
19 | print("Hello 2");
20 | return 2;
21 | }
22 | }
23 |
24 | function main() {
25 | const cls1 = new Cls1();
26 | assert(cls1.foo() == 1);
27 |
28 | const ifoo: Ifaces.IFoo = cls1;
29 | assert(ifoo.foo() == 1);
30 |
31 | const ifoo2: IFoo = cls1;
32 | assert(ifoo2.foo() == 1);
33 | assert(ifoo2.foo2() == 2);
34 |
35 | const ifoo3 = cls1 as Ifaces.IFoo;
36 | assert(ifoo3.foo() == 1);
37 |
38 | print("done.");
39 | }
40 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00interface2.ts:
--------------------------------------------------------------------------------
1 | class S {
2 | print() {
3 | print("Hello World");
4 | }
5 | }
6 |
7 | interface IPrn {
8 | print();
9 | }
10 |
11 | function run(iface: IPrn) {
12 | iface.print();
13 | }
14 |
15 | function main() {
16 | const s = new S();
17 | let iface = s;
18 | iface.print();
19 | run(s);
20 |
21 | print("done.");
22 | }
23 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00interface_generic.ts:
--------------------------------------------------------------------------------
1 | interface I {
2 | foo(x: number): T;
3 | }
4 |
5 | interface A extends I/*, I*/ { }
6 |
7 | class AI {
8 | foo(x: number) { return x; }
9 | }
10 |
11 | function main() {
12 | let x: A = new AI();
13 | const r = x.foo(1); // no error
14 | //const r2 = x.foo(''); // error
15 |
16 | assert(r == 1);
17 |
18 | let x2: I = new AI();
19 | const r2 = x2.foo(2); // no error
20 |
21 | assert(r2 == 2);
22 |
23 | print("done.");
24 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00interface_new.ts:
--------------------------------------------------------------------------------
1 | interface ClockConstructor {
2 | new(h: number, m: number): ClockInterface;
3 | }
4 |
5 | interface ClockInterface {
6 | tick(): void;
7 | h: number;
8 | m: number;
9 | }
10 |
11 | function main() {
12 | const clockInst: ClockConstructor = class Clock implements ClockConstructor {
13 | constructor(public h: number, public m: number) { print(`Call ctor : ${h}, ${m}`); }
14 | tick() {
15 | print("beep beep");
16 | }
17 | };
18 |
19 | const newInst = new clockInst(1, 2);
20 | newInst.tick();
21 |
22 | assert(newInst.h == 1);
23 | assert(newInst.m == 2);
24 |
25 | print("done.");
26 | }
27 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00interface_object2.ts:
--------------------------------------------------------------------------------
1 | interface Surface {
2 | roughness: number;
3 | }
4 |
5 | module Surfaces {
6 | export let shiny: Surface = {
7 | roughness: 250.0
8 | }
9 | export let checkerboard: Surface = {
10 | roughness: 150.0
11 | }
12 | }
13 |
14 | function main() {
15 | print("Start");
16 |
17 | print(Surfaces.shiny.roughness);
18 | print(Surfaces.checkerboard.roughness);
19 |
20 | assert(Surfaces.shiny.roughness == 250.0);
21 | assert(Surfaces.checkerboard.roughness == 150.0);
22 |
23 | print("done.");
24 | }
25 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00interface_object3.ts:
--------------------------------------------------------------------------------
1 | interface IFace {
2 | print: () => void;
3 | }
4 |
5 | function main() {
6 | const a: IFace = {
7 | val: 5,
8 | print: function () { print("hello", this.val); assert(this.val == 5); }
9 | };
10 | a.print();
11 |
12 | const m = a.print;
13 | m();
14 |
15 | const mt: () => void = a.print;
16 | mt();
17 |
18 | print("done.");
19 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00interface_object4.ts:
--------------------------------------------------------------------------------
1 | interface Shape {
2 | color: string;
3 | }
4 |
5 | interface PenStroke {
6 | penWidth: number;
7 | }
8 |
9 | interface Square extends Shape, PenStroke {
10 | sideLength: number;
11 | }
12 |
13 | function main()
14 | {
15 | let square = {} as Square;
16 | square.color = "blue";
17 | square.sideLength = 10;
18 | square.penWidth = 5.0;
19 |
20 | print(`${square.color}, ${square.sideLength}, ${square.penWidth}`);
21 |
22 | assert(square.color == "blue");
23 | assert(square.sideLength == 10);
24 | assert(square.penWidth == 5.0);
25 |
26 | print("done.");
27 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00interface_object5.ts:
--------------------------------------------------------------------------------
1 | interface Point {
2 | x: number;
3 | y: number;
4 |
5 | fromOrigin(p: Point): number;
6 | }
7 |
8 | const o = {
9 | x:1,
10 | y:2,
11 | fromOrigin(p: Point) { return 3.0; }
12 | };
13 |
14 | const iface: Point = o;
15 |
16 | print(iface.x);
17 | print(iface.y);
18 | print(iface.fromOrigin(iface));
19 |
20 | assert(iface.x == 1);
21 | assert(iface.y == 2);
22 | assert(iface.fromOrigin(iface) == 3.0);
23 |
24 | print("done.")
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00interface_optional.ts:
--------------------------------------------------------------------------------
1 | // @strict: true
2 | interface IFace {
3 | cond0: boolean;
4 | cond1?: boolean;
5 | }
6 |
7 | function main() {
8 |
9 | const a: IFace = { cond0: true };
10 |
11 | print(a.cond0);
12 | print(a.cond1 == undefined);
13 | print(a.cond1);
14 |
15 | assert(a.cond0);
16 | assert(a.cond1 == undefined);
17 |
18 | // a.cond1?.value
19 |
20 | print("done.");
21 | }
22 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00interface_partial.ts:
--------------------------------------------------------------------------------
1 | interface Box {
2 | height: number;
3 | width: number;
4 | }
5 |
6 | interface Box {
7 | scale: number;
8 | }
9 |
10 | function main() {
11 | let box: Box = { height: 5, width: 6, scale: 10 };
12 |
13 | assert(box.height == 5);
14 | assert(box.width == 6);
15 | assert(box.scale == 10);
16 |
17 | print(box.height, box.width, box.scale);
18 |
19 | print("done.");
20 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00intersection_type.ts:
--------------------------------------------------------------------------------
1 | interface CreateArtistBioBase {
2 | artistID: string;
3 | thirdParty?: boolean;
4 | }
5 |
6 | type CreateArtistBioRequest = CreateArtistBioBase & ({ html: string } | { markdown: string });
7 |
8 | const workingRequest: CreateArtistBioRequest = {
9 | artistID: "banksy",
10 | markdown: "Banksy is an anonymous England-based graffiti artist...",
11 | };
12 |
13 | function main() {
14 | print("done.");
15 | }
16 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00intersection_type_generic.ts:
--------------------------------------------------------------------------------
1 | function extend(first: T, second: U): T & U {
2 | let result = { ...first, ...second };
3 | return result;
4 | }
5 |
6 | function main()
7 | {
8 | const x = extend({ a: "hello" }, { b: 42 });
9 | const s = x.a;
10 | const n = x.b;
11 |
12 | print (s);
13 | print (n);
14 |
15 | assert (s === "hello");
16 | assert (n === 42);
17 |
18 | print("done.");
19 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00iterator.ts:
--------------------------------------------------------------------------------
1 | function main() {
2 | let arr = [1, 2, 3];
3 |
4 | const it = (function* () { for (const v of arr) yield ((x: typeof v) => x + 1)(v); })();
5 |
6 | for (const v of it) print(v);
7 |
8 | const it2 = (function* () { for (const v of arr) yield ((x: T) => x + 1)(v); })();
9 |
10 | for (const v of it2) print(v);
11 |
12 | print("done.");
13 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00iterator_bug.ts:
--------------------------------------------------------------------------------
1 | class MatchResults
2 | {
3 | constructor() {
4 | }
5 |
6 | [index: number]: string;
7 |
8 | get(index: number) {
9 | return "";
10 | }
11 |
12 | get length() {
13 | return 0;
14 | }
15 | }
16 |
17 | function exec(): MatchResults | null {
18 | return new MatchResults();
19 | }
20 |
21 | type IterateResult = { value: T, done: boolean };
22 |
23 | interface Iterator {
24 | next: () => IterateResult;
25 | }
26 |
27 | function *matchAll(): Iterator {
28 |
29 | while (true)
30 | {
31 | const result = exec();
32 | if (result == null)
33 | break;
34 |
35 | yield [...result];
36 | }
37 | }
38 |
39 | for (const v of matchAll()) { print("ok."); break; }
40 |
41 | print("done.");
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00lambdas_generic_global.ts:
--------------------------------------------------------------------------------
1 | const convert = (value: U): U => value;
2 |
3 | function main()
4 | {
5 | const v:string = convert("asd");
6 |
7 | print(v);
8 |
9 | assert(v == "asd");
10 |
11 | print("done.");
12 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00length.ts:
--------------------------------------------------------------------------------
1 | function main() {
2 | const a = "asd";
3 | print(a.length);
4 |
5 | for (let b = 0; b < a.length; b++) {
6 | print(a[b]);
7 | }
8 |
9 | for (let d = 0; d < [1, 2, 3].length; d++) {
10 | print([1, 2, 3][d]);
11 | }
12 |
13 | print("done.");
14 | }
15 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00map.ts:
--------------------------------------------------------------------------------
1 | function main() {
2 | let arr = [1, 2, 3];
3 |
4 | for (const v of arr.map(x => x + 1)) print(v);
5 |
6 | let arrS = ["asd", "asd2"];
7 | for (const e of arrS.map((e) => e + "_")) print(e);
8 |
9 | print("done.");
10 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00method_access_cond.ts:
--------------------------------------------------------------------------------
1 | // @strict-null false
2 | class C {
3 | val: number;
4 |
5 | constructor() {
6 | this.val = 2;
7 | }
8 |
9 | print() {
10 | print("Hello World");
11 | }
12 |
13 | getVal() {
14 | return 10;
15 | }
16 | }
17 |
18 | function o(val: C) {
19 | val?.print();
20 | print(val?.getVal());
21 | }
22 |
23 | function main() {
24 | o(new C());
25 | o(null);
26 | print("done.");
27 | }
28 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00names_conflict.ts:
--------------------------------------------------------------------------------
1 | function main()
2 | {
3 | type A = number;
4 | const A = "asd";
5 | const b: A = 1;
6 |
7 | print(b, A);
8 |
9 | assert(A == "asd" && b == 1);
10 |
11 | print("done.");
12 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00new_delete.ts:
--------------------------------------------------------------------------------
1 | type Type1 = TypeOf<1>;
2 |
3 | function test_int() {
4 | let i = new Type1();
5 | delete i;
6 | }
7 |
8 | function test_array() {
9 | let a: number[] = [];
10 | a.length = 10;
11 | a[0] = 1;
12 | print(a[0]);
13 |
14 | let b = a;
15 | b[1] = 2;
16 | print(b[0], b[1]);
17 |
18 | delete a;
19 | }
20 |
21 | function main() {
22 | test_int();
23 | test_array();
24 | print("done.");
25 | }
26 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00ns.ts:
--------------------------------------------------------------------------------
1 | namespace nn {
2 | function ff() {
3 | print("hello");
4 | }
5 |
6 | function fff() {
7 | ff();
8 | }
9 | }
10 |
11 | function f() {
12 | print("hello");
13 | }
14 |
15 | namespace nn1 {
16 | type Type1 = TypeOf<1>;
17 | }
18 |
19 | function f1(p: nn1.Type1) {}
20 |
21 | function main() {
22 | f();
23 | nn.fff();
24 | f1(10);
25 | print("done.");
26 | }
27 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00ns3.ts:
--------------------------------------------------------------------------------
1 | let glb1 = 0;
2 |
3 | namespace fooX.bar.baz {
4 | export function b() {
5 | glb1++;
6 | }
7 | }
8 |
9 | import bz = fooX.bar.baz;
10 | function testImports() {
11 | glb1 = 0;
12 | bz.b();
13 | assert(glb1 == 1, "imports");
14 | }
15 |
16 | function main() {
17 | testImports();
18 | print("done.");
19 | }
20 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00ns4.ts:
--------------------------------------------------------------------------------
1 | let glb1 = 10;
2 | namespace fooX.bar.baz {
3 | let glb1 = 1;
4 |
5 | export function b() {
6 | glb1++;
7 | assert(glb1 == 2, "fooX.bar.baz.glb1");
8 | }
9 | }
10 |
11 | import bz = fooX.bar.baz;
12 | function main() {
13 | bz.b();
14 | assert(glb1 == 10, "glb1");
15 | assert(bz.glb1 == 2, "glb1");
16 | print("done.");
17 | }
18 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00ns5.ts:
--------------------------------------------------------------------------------
1 | namespace nn {
2 | class c1 {}
3 | }
4 |
5 | function main() {
6 | const c = new nn.c1();
7 | delete c;
8 | print("done.");
9 | }
10 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00ns_bug.ts:
--------------------------------------------------------------------------------
1 | interface IData
2 | {
3 | data: T;
4 | }
5 |
6 | namespace ifaces
7 | {
8 | export interface IData
9 | {
10 | data: T;
11 | }
12 |
13 | export interface IData2
14 | {
15 | data: string;
16 | }
17 | }
18 |
19 | namespace test {
20 | function f() : ifaces.IData {
21 | return { data: ["Hello"] };
22 | }
23 |
24 | function f2() : ifaces.IData2 {
25 | return { data: "Hello" };
26 | }
27 |
28 | function f3() : IData {
29 | return { data: ["Hello"] };
30 | }
31 | }
32 |
33 | const d = test.f();
34 | const d2 = test.f2();
35 | const d3 = test.f3();
36 |
37 | print("done.");
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00object_accessor.ts:
--------------------------------------------------------------------------------
1 | let obj = {
2 | p: 1.0,
3 | get value() { return this.p; },
4 | set value(v: number) { this.p = v; },
5 | }
6 |
7 | const t1 = {
8 | p: 'value',
9 | get getter() {
10 | return 'value';
11 | },
12 | }
13 |
14 | const t2 = {
15 | v: 'value',
16 | set setter(v: 'value') {},
17 | }
18 |
19 | function main() {
20 | assert(obj.value == 1.0);
21 |
22 | obj.value = 20;
23 |
24 | assert(obj.value == 20.0);
25 |
26 | print(t1.getter);
27 | t2.setter = 'value';
28 |
29 | print("done.");
30 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00object_func2.ts:
--------------------------------------------------------------------------------
1 | function call_func_1(f: () => void) {
2 | f();
3 | }
4 |
5 | function call_func(f: (o: object) => void, user: { firstName: string }) {
6 | f(user);
7 | }
8 |
9 | function call_func2(f: (o: unknown) => void, user: { firstName: string }) {
10 | f(user);
11 | }
12 |
13 | function main() {
14 | const user = {
15 | firstName: "World",
16 | sayHi() {
17 | print(`Hello ${this.firstName}`);
18 | },
19 | };
20 |
21 | user.sayHi();
22 |
23 | const hi = user.sayHi;
24 | hi();
25 |
26 | let hi2 = user.sayHi;
27 | hi2();
28 |
29 | call_func_1(() => {
30 | hi2();
31 | });
32 |
33 | call_func(user.sayHi, user);
34 | // We do not allow it
35 | //call_func2(user.sayHi, user);
36 |
37 | print("done.");
38 | }
39 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00object_func3.ts:
--------------------------------------------------------------------------------
1 | function main() {
2 |
3 | let obj = {
4 | val: 10,
5 | add: () => {
6 | add_();
7 |
8 | function add_() {
9 | if (++this.val < 15) this.add();
10 | }
11 | }
12 | };
13 |
14 | obj.add();
15 | print(obj.val);
16 |
17 | assert(obj.val === 15);
18 |
19 | main2();
20 |
21 | print("done.");
22 | }
23 |
24 | function main2()
25 | {
26 | let o2 = { a: 1, 'b': 2, ['c']: 3, d() { }, ['e']: 4 } as const;
27 | let o9 = { x: 10, foo() { this.x = 20 } } as const;
28 |
29 |
30 | o2.d();
31 | o9.foo();
32 |
33 | assert(o9.x == 20);
34 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00object_global.ts:
--------------------------------------------------------------------------------
1 | let a = {
2 | a: 1
3 | };
4 |
5 | let deck = {
6 | suits: ["hearts", "spades", "clubs", "diamonds"],
7 | cards: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],
8 | createCardPicker: function () {
9 | // NOTE: the line below is now an arrow function, allowing us to capture 'this' right here
10 | return () => {
11 | return { suit: this.suits[1], card: 2 };
12 | };
13 | },
14 | };
15 |
16 | function main() {
17 | assert(a.a == 1);
18 |
19 | let cardPicker = deck.createCardPicker();
20 | let pickedCard = cardPicker();
21 |
22 | assert(pickedCard.card == 2);
23 | assert(pickedCard.suit == "spades");
24 |
25 | print("done.");
26 | }
27 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00object_new.ts:
--------------------------------------------------------------------------------
1 | let called = false;
2 |
3 | class B {
4 | constructor(x: number, y: number, ...z: string[]) { print("constr", x, y); called = true; }
5 | }
6 |
7 | function main() {
8 |
9 | let dd : {
10 | new(x: number, y: number, ...z: string[]): B;
11 | } = B;
12 |
13 | const ss = new dd(1, 2);
14 |
15 | assert(called);
16 |
17 | print("done.");
18 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00optional.ts:
--------------------------------------------------------------------------------
1 | function math() {
2 | let v: number | undefined;
3 | v = 1;
4 | print(v);
5 | assert(v == 1);
6 | v += 2;
7 | print(v);
8 | assert(v == 3);
9 | v += v;
10 | print(v);
11 | assert(v == 6);
12 | v++;
13 | print(v);
14 | assert(v == 7);
15 | --v;
16 | print(v);
17 | assert(v == 6);
18 | }
19 |
20 | function logic() {
21 | let v1: number | undefined;
22 | v1 = 1;
23 | let v2: number | undefined;
24 | v2 = 10;
25 |
26 | assert(v1 < v2);
27 | assert(v1 < v2);
28 |
29 | assert(v1 != v2);
30 | assert(v1 != v2);
31 |
32 | assert(!(v1 >= v2));
33 | assert(!(v1 >= v2));
34 |
35 | assert(!(v1 == v2));
36 | assert(!(v1 == v2));
37 | }
38 |
39 | function main() {
40 | math();
41 | logic();
42 | print("done.");
43 | }
44 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00prefix_postfix.ts:
--------------------------------------------------------------------------------
1 | function main() {
2 | let j = 0;
3 | print(++j);
4 | print(j++);
5 | print(j);
6 |
7 | print(--j);
8 | print(j--);
9 | print(j);
10 |
11 | print("done.");
12 | }
13 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00print.ts:
--------------------------------------------------------------------------------
1 | function main() {
2 | print("done.");
3 | }
4 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00property_access_cond.ts:
--------------------------------------------------------------------------------
1 | // @strict-null false
2 | class C {
3 | val: number;
4 |
5 | constructor() {
6 | this.val = 2;
7 | }
8 | }
9 |
10 | function o(val?: C) {
11 | print(val?.val);
12 | }
13 |
14 | function main() {
15 | o(new C());
16 | o(null);
17 | o();
18 |
19 | print("done.")
20 | }
21 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00question_question.ts:
--------------------------------------------------------------------------------
1 | // @strict-null false
2 | interface ReturnVal {
3 | something(): void;
4 | }
5 |
6 | function run(options: { something?(): void }, val: ReturnVal) {
7 | const something = options.something ?? val.something;
8 | something();
9 | }
10 |
11 | let glb1 = false;
12 | function main() {
13 | run({ something() { print("something"); glb1 = true; } }, null);
14 | assert(glb1);
15 | print("done.");
16 | }
17 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00reduce.ts:
--------------------------------------------------------------------------------
1 | function main() {
2 | let sum = [1, 2, 3].reduce((s, v) => s + v, 0)
3 |
4 | print(sum);
5 |
6 | assert(sum == 6, "red")
7 |
8 | print("done.");
9 | }
10 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00reference_index_bug.ts:
--------------------------------------------------------------------------------
1 | // @strict-null false
2 |
3 | let a = [1, 2, 3];
4 |
5 | let pa = ReferenceOf(a[0]);
6 |
7 | assert(LoadReference(pa[0]) == 1);
8 | assert(LoadReference(pa[1]) == 2);
9 | assert(LoadReference(pa[2]) == 3);
10 |
11 | print("done.");
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00reference_null_bug.ts:
--------------------------------------------------------------------------------
1 | // @strict-null false
2 |
3 | type tm = [tm_sec: i32, tm_min: i32, tm_hour: i32, tm_mday: i32, tm_mon: i32, tm_year: i32, tm_wday: i32, tm_yday: i32, tm_isdst: i32];
4 | const r: Reference = null;
5 |
6 | let a = false;
7 |
8 | if (r == null)
9 | a = true;
10 |
11 | assert(a);
12 |
13 | print("done.");
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00safe_cast2.ts:
--------------------------------------------------------------------------------
1 | class Cat { name = "kitty"; meow() { print("meow"); } }
2 | class Dog { name = "doggy"; bark() {} }
3 |
4 | function isCat(a: Cat | Dog): a is Cat {
5 | return a.name === "kitty";
6 | }
7 |
8 | function main() {
9 | let x: Cat | Dog = new Cat();
10 | if (isCat(x)) {
11 | x.meow(); // OK, x is Cat in this block
12 | }
13 |
14 | print("done.");
15 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00safe_cast_bug.ts:
--------------------------------------------------------------------------------
1 | let array1: string | number | null = 0;
2 |
3 | let calls = 0;
4 | function exec(str1: string): string | null
5 | {
6 | calls ++;
7 | if (calls <= 1) return "asd";
8 | return null;
9 | }
10 |
11 | while ((array1 = exec("str1")) !== null) {
12 | if (array1 == null) print("ok");
13 | print("while loop");
14 |
15 | if (calls > 3) assert(false);
16 | }
17 |
18 | assert(calls == 2);
19 |
20 | print("calls = ", calls);
21 | print("done.");
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00safe_cast_field_access.ts:
--------------------------------------------------------------------------------
1 | class A {
2 |
3 | private data: number | null = 10;
4 |
5 | constructor() {
6 | print("A");
7 | }
8 |
9 | get x(): number | null {
10 | return 1;
11 | }
12 |
13 | test() {
14 | if (this.data !== null) {
15 | print(this.data);
16 | }
17 | }
18 | }
19 |
20 | const a = new A();
21 |
22 | if (a.x !== null) {
23 | print(a.x);
24 | }
25 |
26 | a.test();
27 |
28 | print("done.");
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00safe_cast_typeof.ts:
--------------------------------------------------------------------------------
1 | // @strict-null false
2 | function gen(t: T)
3 | {
4 | if (typeof t == "array")
5 | {
6 | return t.length;
7 | }
8 |
9 | return "int";
10 | }
11 |
12 | const v1 = gen(23);
13 | print(v1);
14 |
15 | const v2 = gen(null);
16 | print(v2);
17 |
18 | print("done.");
19 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00safe_cast_while.ts:
--------------------------------------------------------------------------------
1 | function get(i: number): string | null
2 | {
3 | return i % 2 ? "test" : null;
4 | }
5 |
6 | let a: string | null = null;
7 |
8 | a = get(1);
9 |
10 | print(a === "test");
11 |
12 | let r = false;
13 | while (a !== null) {
14 | r = true;
15 | assert(a === "test");
16 | print(a, a === "test");
17 | break;
18 | }
19 |
20 | assert(r);
21 |
22 | print("done.")
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00sizeof.ts:
--------------------------------------------------------------------------------
1 | function main() {
2 | print(sizeof(1));
3 |
4 | const cc = ["asd", 10];
5 |
6 | print(sizeof(cc));
7 |
8 | const cc2 = [1.0, 10];
9 |
10 | print(sizeof(cc2));
11 |
12 | const a1 = [1.0, 2.0, 3.0, 4.0];
13 |
14 | print(sizeof(a1));
15 |
16 | print("done.");
17 | }
18 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00stack_test.ts:
--------------------------------------------------------------------------------
1 | function cycle() {
2 | print("start...1");
3 |
4 | for (let i = 0; i < 1000000; i++) {
5 | print(`val : ${i}`);
6 | }
7 |
8 | print("end.");
9 | }
10 |
11 | function cycle_with_func() {
12 | print("start...2");
13 |
14 | let i = 2;
15 |
16 | let f = () => { return i; };
17 |
18 | for (let i = 0; i < 1000000; i++) {
19 | let r = f() + i;
20 | print(`val : ${r}`);
21 | }
22 |
23 | print("end.");
24 |
25 | }
26 |
27 | function main() {
28 | cycle();
29 | cycle_with_func();
30 | print("done.");
31 | }
32 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00strings.ts:
--------------------------------------------------------------------------------
1 | function display(id: number, name: string) {
2 | print("Id = " + id + ", Name = " + name);
3 | }
4 |
5 | function main() {
6 | display(1, "asd");
7 |
8 | print("asd" + 1 == "asd" + "1");
9 | print("asd" + 1 > "Asd1");
10 | print("asd" + 1 <= "Asd1");
11 | print("Asd" + 1 < "asd1");
12 | print("Asd" + 1 >= "asd1");
13 |
14 | print("done.");
15 | }
16 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00switch_state.ts:
--------------------------------------------------------------------------------
1 | function foo(v = 0) {
2 | switchstate(v);
3 | print("Hello 0");
4 | state1: ;
5 | print("Hello 1");
6 | state2: ;
7 | print("Hello 2");
8 | state3: ;
9 | print("Hello 3");
10 | }
11 |
12 | function main() {
13 | foo(2);
14 | print("done.");
15 | }
16 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00to_primitive_ops.ts:
--------------------------------------------------------------------------------
1 | class Val
2 | {
3 | constructor(public value: number) {
4 | }
5 |
6 | [Symbol.toPrimitive](hint: string) {
7 | if (hint === 'number') {
8 | return this.value;
9 | }
10 |
11 | return this.value;
12 | }
13 | }
14 |
15 | const v = new Val(1);
16 | assert((v + 1) == 2);
17 | assert((1 + v) == 2);
18 | assert((v + v) == 2);
19 |
20 | print("done.");
21 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00try_catch_rethrow.ts:
--------------------------------------------------------------------------------
1 | function main() {
2 |
3 | let i = 0;
4 |
5 | try {
6 | try {
7 | throw 1;
8 | }
9 | catch
10 | {
11 | i++;
12 | print("asd1");
13 | throw 2;
14 | }
15 | }
16 | catch
17 | {
18 | i++;
19 | print("asd3");
20 | }
21 |
22 | assert(i == 2);
23 |
24 | print("done.");
25 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00try_catch_return.ts:
--------------------------------------------------------------------------------
1 | let called = false;
2 |
3 | function may_throw(a = 0) {
4 | if (a > 100) throw 1;
5 | }
6 |
7 | function func1() {
8 |
9 | try {
10 | print("In try");
11 | may_throw(1000);
12 | }
13 | catch (e: TypeOf<1>) {
14 | print("catch");
15 | return;
16 | }
17 | finally {
18 | print("finally");
19 | called = true;
20 | }
21 |
22 | called = false;
23 | print("end");
24 | }
25 |
26 | function main() {
27 | func1();
28 | assert(called, "finally is not called");
29 | print("done.");
30 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00tuple_named.ts:
--------------------------------------------------------------------------------
1 | function main() {
2 | let a: [name: string, age: number];
3 |
4 | a.name = "Test1";
5 |
6 | print(a.name, " << end (should be value Test1)");
7 |
8 | let b: [name: string, age: number, _8: number] = ["user", 10.0, 20.0];
9 |
10 | print(b.name, b.age, b._8);
11 |
12 | let c: [user: [name: string, age: number], type: number] = [["user2", 11.0], 1.0];
13 |
14 | print(c.user.name, c.user.age, c.type);
15 | print(c.user.name);
16 |
17 | c.user.name = "Test2";
18 |
19 | assert(c.user.name == "Test2");
20 |
21 | print(c.user.name, " << end (should be value Test2)");
22 |
23 | let a: [v1: number, v2: string];
24 | a = [10.0 + 20.0, "asd"];
25 |
26 | print(a.v1, a.v2);
27 |
28 | assert(a.v1 == 30.0);
29 | assert(a.v2 == "asd");
30 |
31 | print("done.");
32 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00tuple_with_array.ts:
--------------------------------------------------------------------------------
1 | function main() {
2 | const trees = [
3 | [1, "redwood", [1]],
4 | [2, "bay", [1, 2]],
5 | [3, "cedar", [1, 2, 3]],
6 | [4, "oak", [1, 2, 3, 4]],
7 | [5, "maple", [1, 2, 3, 4, 5]],
8 | ];
9 |
10 | for (const [k, v, a] of trees) {
11 | print(k, v);
12 |
13 | for (const ai of a) {
14 | print(ai);
15 | }
16 | }
17 |
18 | print("done.");
19 | }
20 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00type_aliases_in_generics.ts:
--------------------------------------------------------------------------------
1 | type ObjectDescriptor = {
2 | data?: D;
3 | methods?: M/* & ThisType*/; // Type of 'this' in methods is D & M
4 | };
5 |
6 | function makeObject(desc: ObjectDescriptor): D & M {
7 | let data = desc.data/* || {}*/;
8 | let methods = desc.methods/* || {}*/;
9 | return { ...data, ...methods } as D & M;
10 | }
11 |
12 | function main() {
13 |
14 | let obj = makeObject({
15 | data: { x: 0, y: 0 },
16 | methods: {
17 | moveBy(dx: number, dy: number) {
18 | //this.x += dx; // Strongly typed this
19 | //this.y += dy; // Strongly typed this
20 | },
21 | },
22 | });
23 |
24 | obj.x = 10;
25 | obj.y = 20;
26 | obj.moveBy(5, 5);
27 |
28 | print("done.");
29 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00type_guard_function.ts:
--------------------------------------------------------------------------------
1 | class A {
2 | propA: number;
3 | }
4 |
5 | class B {
6 | propB: number;
7 | }
8 |
9 | class C extends A {
10 | propC: number;
11 | }
12 |
13 | // TODO: union is not working here, why?
14 | function isA(p1: any): p1 is A {
15 | return p1 instanceof A;
16 | }
17 |
18 | function isB(p1: A | B | C): p1 is B {
19 | return p1 instanceof B;
20 | }
21 |
22 | function isC(p1: A | B | C): p1 is C {
23 | return p1 instanceof C;
24 | }
25 |
26 | function main() {
27 |
28 | //let abc: A | B | C = new A();
29 | let abc = new A();
30 |
31 | if (isA(abc)) {
32 | print("this is A");
33 | abc.propA;
34 | }
35 |
36 | if (isB(abc)) {
37 | print("this is B");
38 | abc.propB;
39 | }
40 |
41 | if (isC(abc)) {
42 | print("this is C");
43 | abc.propC;
44 | }
45 |
46 | print("done.");
47 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00typed_array.ts:
--------------------------------------------------------------------------------
1 | type Uint8Array = u8[];
2 | type Uint16Array = u16[];
3 |
4 | function main() {
5 | const arr = new Uint8Array(10);
6 | const elem = arr[0];
7 | print(typeof elem);
8 | //print(elem);
9 |
10 | let arr2 = new Uint16Array();
11 | arr2.push(2);
12 | const elem2 = arr2[0];
13 | print(typeof elem2);
14 | //print(elem2);
15 |
16 | print("done.");
17 | }
18 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00types.ts:
--------------------------------------------------------------------------------
1 | function s(v: any): v is string {
2 | return typeof v === "string";
3 | }
4 |
5 | class X {
6 | v = 10;
7 | a(p: this) {
8 | print("Hello...");
9 | print("Hello", this.v);
10 | print("Hello", p.v);
11 | return p;
12 | }
13 | }
14 |
15 | interface I {
16 | a: (p: this) => this;
17 | }
18 |
19 | function main() {
20 | assert(s("sss"));
21 |
22 | let x = new X();
23 | assert(x.a(x).v == 10);
24 |
25 | let x2: I = {
26 | a(p: I) {
27 | return p;
28 | }
29 | }
30 |
31 | let y = x2.a(x2);
32 |
33 | print("done.")
34 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00types_indexedaccesstype.ts:
--------------------------------------------------------------------------------
1 | type Person = { age: number; name: string; alive: boolean };
2 | type Age = Person["age"];
3 |
4 | type I1 = Person["age" | "name"];
5 |
6 | type I2 = Person[keyof Person];
7 |
8 | function main() {
9 |
10 | let a: Age = 10.0;
11 |
12 | let b: I1;
13 |
14 | let c: I2;
15 |
16 | print("done.");
17 | }
18 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00types_keyof_enum.ts:
--------------------------------------------------------------------------------
1 | const enum TestType { foo, bar }
2 | type TestTypeStr = keyof typeof TestType;
3 |
4 | function f1(f: TestType) { }
5 | function f2(f: TestTypeStr) { }
6 |
7 | function main() {
8 | f1(TestType.foo)
9 | f1(TestType.bar)
10 | f2('foo')
11 | f2('bar')
12 |
13 | print("done.");
14 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00uint_compare_bug.ts:
--------------------------------------------------------------------------------
1 | let i = -1;
2 |
3 | let ui = i;
4 |
5 | let len: uint = 200
6 |
7 | let cmp = ui < len;
8 |
9 | print(i, ui, 200, cmp, 4294967295 < 200);
10 |
11 | assert(cmp == false);
12 |
13 | print("done.");
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00union_bin_ops.ts:
--------------------------------------------------------------------------------
1 | let a: string | number = 1;
2 |
3 | let b: string | number = "2";
4 |
5 | const c = a + b;
6 |
7 | assert(c === "12");
8 |
9 | print("done.");
10 |
11 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00union_bin_ops2.ts:
--------------------------------------------------------------------------------
1 | class Val {
2 | constructor(public value: number) {
3 | }
4 |
5 | [Symbol.toPrimitive](hint: string) {
6 | if (hint === 'number') {
7 | return this.value;
8 | }
9 |
10 | return this.value;
11 | }
12 | }
13 |
14 | let a2: string | number | Val = new Val(1);
15 | let b2: string | number | Val = '1';
16 |
17 | let c2 = a2 + b2;
18 | print(c2);
19 |
20 | assert(c2 == "11");
21 |
22 | print("done.");
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00union_errors.ts:
--------------------------------------------------------------------------------
1 | type TokenType = "NUMBER" | "PLUS" | "MINUS" | "MULTIPLY" | "DIVIDE" | "LEFT_PAREN" | "RIGHT_PAREN" | "EOF";
2 |
3 | let v: TokenType = "PLUS";
4 | let v2: TokenType = "DIVIDE";
5 |
6 | assert(v === "PLUS")
7 | assert(v !== "MINUS")
8 |
9 | assert(v === v)
10 | assert(v !== v2)
11 |
12 |
13 | let a: number | null = 1.0;
14 |
15 | if (a !== null) {
16 | let r = a + 1;
17 | print (r);
18 | assert(r == 2.0);
19 | }
20 |
21 | print("done.")
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00union_ops.ts:
--------------------------------------------------------------------------------
1 | function main() {
2 | let a: string | undefined
3 | let b: string | undefined
4 | let c: string | undefined
5 |
6 | let d: number | undefined
7 | let e: number | undefined
8 | let f: string | undefined
9 |
10 | let g: 0 | 1 | 42
11 | let h: 0 | 1 | 42
12 | let i: 0 | 1 | 42
13 |
14 |
15 | a &&= "foo"
16 | b ||= "foo"
17 | c ??= "foo"
18 |
19 |
20 | d &&= 42
21 | e ||= 42
22 | f ??= "42" // must be ref type
23 |
24 | g &&= 42
25 | h ||= 42
26 | i ??= 42
27 |
28 | print("done.");
29 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00union_to_any.ts:
--------------------------------------------------------------------------------
1 | // TODO: union of classes should be -> root class = class object, but first you need to create __object root class for all classes
2 | class A {
3 | propA: number;
4 | }
5 |
6 | class B {
7 | propB: number;
8 | }
9 |
10 | function isA(p1: any): p1 is A {
11 | return p1 instanceof A;
12 | }
13 |
14 | function main() {
15 | // Union type
16 | const a = new A();
17 | a.propA = 10;
18 | let union: A | B = a;
19 | if (isA(union)) {
20 | print("this is A");
21 | assert(union.propA == 10);
22 | }
23 | else
24 | {
25 | assert(false);
26 | }
27 |
28 | print("done.");
29 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00union_type.ts:
--------------------------------------------------------------------------------
1 | function testUnionIndexer(): void {
2 | type SmallNumber = (0 | 1) | (1 | 2) | 2;
3 | const arr: string[] = ["foo", "bar", "baz"];
4 |
5 | let index: SmallNumber = 0;
6 | assert(arr[index] === arr[0]);
7 |
8 | index = 1;
9 | assert(arr[index] === arr[1]);
10 |
11 | // need to cast to get past typescript narrowing without randomness
12 | index = 2 as SmallNumber;
13 | if (index === 0) {
14 | return;
15 | }
16 |
17 | assert(arr[index] === arr[2]);
18 | }
19 |
20 | function main() {
21 | testUnionIndexer();
22 | print("done.");
23 | }
24 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00void.ts:
--------------------------------------------------------------------------------
1 | function main() {
2 | print(void 2 == "2"); // (void 2) == '2', returns false
3 | print(void (2 == "2")); // void (2 == '2'), returns undefined
4 |
5 | print("done.");
6 | }
7 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/00while.ts:
--------------------------------------------------------------------------------
1 | function main() {
2 | assert(test() == 0, "failed. 1");
3 |
4 | print("done.");
5 | }
6 |
7 | function test() {
8 | let i = 0;
9 | while (i > 0) {
10 | print(i--);
11 | }
12 |
13 | return i;
14 | }
15 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/01class_new.ts:
--------------------------------------------------------------------------------
1 | interface Boolean {
2 | /** Returns the primitive value of the specified object. */
3 | valueOf(): boolean;
4 | }
5 |
6 | interface BooleanConstructor {
7 | new(value?: boolean): Boolean;
8 | }
9 |
10 | class BooleanImpl implements BooleanConstructor {
11 | value: boolean;
12 |
13 | constructor(value?: boolean) {
14 | this.value = value;
15 | }
16 |
17 | valueOf(): boolean {
18 | return this.value;
19 | }
20 | }
21 |
22 | function main() {
23 | const Boolean: BooleanConstructor = new BooleanImpl();
24 | const b = new Boolean(true);
25 | print(b.valueOf());
26 |
27 | assert(b.valueOf());
28 |
29 | print("done.");
30 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/01disposable.ts:
--------------------------------------------------------------------------------
1 | let count_created = 0;
2 | let count_disp = 0;
3 | function loggy(id: string) {
4 | print(`Creating ${id}`);
5 | count_created++;
6 | return {
7 | [Symbol.dispose]() {
8 | print(`Disposing ${id}`);
9 | count_disp++;
10 | }
11 | }
12 | }
13 |
14 | function func() {
15 | using a = loggy("a");
16 | using b = loggy("b");
17 | {
18 | using c = loggy("c");
19 | using d = loggy("d");
20 | }
21 | using e = loggy("e");
22 | return;
23 | // Unreachable.
24 | // Never created, never disposed.
25 | using f = loggy("f");
26 | }
27 |
28 | function func2(i = 0) {
29 | using a = loggy("a");
30 | if (i > 0) return;
31 | }
32 |
33 | function main() {
34 | func();
35 | func2();
36 |
37 | assert(count_created == count_disp, "not equal create-dispose");
38 |
39 | print("done.");
40 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/01enum.ts:
--------------------------------------------------------------------------------
1 | // @declaration: true
2 |
3 | // An enum declaration that specifies a const modifier is a constant enum declaration.
4 | // In a constant enum declaration, all members must have constant values and
5 | // it is an error for a member declaration to specify an expression that isn't classified as a constant enum expression.
6 |
7 | const enum E {
8 | a = 10,
9 | b = a,
10 | c = (a+1),
11 | e,
12 | d = ~e,
13 | f = a << 2 >> 1,
14 | g = a << 2 >>> 1,
15 | h = a | b,
16 | i = E.a
17 | }
18 |
19 | enum T1 {
20 | a = "1",
21 | b = "1" + "2",
22 | c = "1" + "2" + "3"
23 | }
24 |
25 | enum EComp2 {
26 | A = 'foo'.length, B = 'foo'.length, C = 'foo'.length
27 | }
28 |
29 | function main()
30 | {
31 | assert(E.a === E.i);
32 | assert(T1.c === "123");
33 | assert(EComp2.C === 3);
34 | print("done.");
35 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/01extends.ts:
--------------------------------------------------------------------------------
1 | let glb1 = 0;
2 |
3 | type ElementOfArray = A extends {
4 | readonly [n: number]: infer T;
5 | } ? T : never;
6 |
7 | type ArrayLike = A extends {
8 | readonly length: number;
9 | readonly [n: number]: ElementOfArray;
10 | } ? A : never;
11 |
12 | function forEach1;
15 | }>(this: A) {
16 | for (const v of this) {
17 | print(v);
18 | glb1++;
19 | }
20 | }
21 |
22 | function forEach2(this: ArrayLike) {
23 | for (const v of this) {
24 | print(v);
25 | glb1++;
26 | }
27 | }
28 |
29 | function main() {
30 | let a = [1, 2, 3.0];
31 |
32 | forEach1(a);
33 |
34 | forEach2(a);
35 |
36 | assert(glb1 == 6);
37 |
38 | print("done.");
39 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/01extension.ts:
--------------------------------------------------------------------------------
1 | interface IFace {
2 | print: () => void;
3 | }
4 |
5 | function printExt(this:IFace)
6 | {
7 | this.print();
8 | }
9 |
10 | function main() {
11 | const a: IFace = {
12 | val: 5,
13 | print: function () { print("hello", this.val); assert(this.val == 5); }
14 | };
15 |
16 | a.printExt();
17 |
18 | const ma = a.printExt;
19 | ma();
20 |
21 | print("done.");
22 | }
23 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/01funcs_generic.ts:
--------------------------------------------------------------------------------
1 | function getProperty(obj: T, key: K) {
2 | //return obj[key]; // Inferred type is T[K]
3 | return 1.0;
4 | }
5 |
6 | function setProperty(obj: T, key: K, value: T[K]) {
7 | //obj[key] = value;
8 | }
9 |
10 | function main() {
11 |
12 | let x = { foo: 10, bar: "hello!" };
13 | let foo = getProperty(x, "foo"); // number
14 | let bar = getProperty(x, "bar"); // string
15 |
16 | // TODO: because in setProperty we send K as 'string' type (should be LiteralType - "foo"
17 | // we can't identify value T[K]
18 |
19 | //setProperty(x, "foo", 1); // number
20 | //setProperty(x, "bar", "2"); // string
21 | print("done.");
22 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/01funcs_vararg.ts:
--------------------------------------------------------------------------------
1 | type Array = T[];
2 |
3 | function foo(...args: T[]): T[]
4 | {
5 | return args;
6 | }
7 |
8 | function main()
9 | {
10 | let b1: { x: boolean }[] = foo({ x: true }, { x: false });
11 | let b2: boolean[][] = foo([true], [false]);
12 |
13 | main2();
14 |
15 | print("done.");
16 | }
17 |
18 | function fn(x: any): void {};
19 | function takeTwo(x: any, y: any): void {};
20 | function withRest(a: any, ...args: Array): void {};
21 |
22 | function main2()
23 | {
24 | let n: number[] = [];
25 |
26 | fn(1) // no error
27 | takeTwo(1, 2)
28 | withRest('a', ...n); // no error
29 | withRest(...n);
30 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/01iterator.ts:
--------------------------------------------------------------------------------
1 | let glb1 = 0;
2 |
3 | function* g() {
4 | yield* [1, 2, 3];
5 | }
6 |
7 | function f() {
8 | for (const x of g()) {
9 | print(x);
10 | glb1++;
11 | }
12 | }
13 |
14 | function main() {
15 | f();
16 |
17 | assert(glb1 == 3);
18 |
19 | print("done.");
20 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/01lambdas.ts:
--------------------------------------------------------------------------------
1 | function reduce2(this: T[], func: (v: V, t: T) => V, initial?: V) {
2 | let result = initial || 0;
3 | for (const v of this) result = func(result, v);
4 | return result;
5 | }
6 |
7 | function main() {
8 |
9 | const array1 = [1, 2, 3, 4];
10 |
11 | // 0 + 1 + 2 + 3 + 4
12 | const initialValue = 0;
13 |
14 | const sumWithInitial2 = array1.reduce2(
15 | (accumulator: int, currentValue) => accumulator + currentValue,
16 | );
17 |
18 | print (sumWithInitial2);
19 |
20 | assert(sumWithInitial2 == 10);
21 |
22 | print ("done.");
23 | }
24 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/01map.ts:
--------------------------------------------------------------------------------
1 | function main() {
2 | const inventory = [
3 | { name: "asparagus", type: "vegetables", quantity: 5 },
4 | { name: "bananas", type: "fruit", quantity: 0 },
5 | { name: "goat", type: "meat", quantity: 23 },
6 | { name: "cherries", type: "fruit", quantity: 5 },
7 | { name: "fish", type: "meat", quantity: 22 },
8 | ];
9 |
10 | for (const v of inventory) print(v.name, v.type, v.quantity);
11 |
12 | for (const r of inventory.map(({ type }) => type)) print(r);
13 |
14 | print("done.");
15 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/01method_access_cond.ts:
--------------------------------------------------------------------------------
1 | function main()
2 | {
3 | let a: { f:() => void } | undefined = undefined;
4 |
5 | print("start");
6 |
7 | a?.f();
8 |
9 | print("done.");
10 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/01optional.ts:
--------------------------------------------------------------------------------
1 | function main() {
2 | type StaffAccount = [number, string, string, string?];
3 |
4 | const staff: StaffAccount[] = [
5 | [0, "Adankwo", "adankwo.e@"],
6 | [1, "Kanokwan", "kanokwan.s@"],
7 | [2, "Aneurin", "aneurin.s@", "Supervisor"],
8 | ];
9 |
10 | for (const v of staff) print(v[0], v[1], v[2], v[3] || "");
11 |
12 | assert(staff[2][3] == "Supervisor");
13 |
14 | print("done.");
15 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/01print-bug.ts:
--------------------------------------------------------------------------------
1 | interface Ray {
2 | start: number;
3 | dir: number;
4 | }
5 |
6 | function test(v: Ray) {
7 | // BUG:
8 | print("v: ", v.start, v.dir);
9 | }
10 |
11 |
12 | function main() {
13 | print("start...");
14 | let p = 1.0;
15 | test({ start: 1.0, dir: p });
16 | print("done.");
17 | }
18 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/01safe_cast_while.ts:
--------------------------------------------------------------------------------
1 | class Lexer {
2 | private currentChar: string | null;
3 |
4 | constructor(text: string) {
5 | this.currentChar = text.length > 0 ? text[0] : null;
6 | }
7 |
8 | getNextToken() {
9 | const currentChar = this.currentChar;
10 | while (currentChar !== null) {
11 | if (currentChar === " ") {
12 | continue;
13 | }
14 |
15 | break;
16 | }
17 |
18 | return true;
19 | }
20 | }
21 |
22 | print("done.")
--------------------------------------------------------------------------------
/tsc/test/tester/tests/01sizeof.ts:
--------------------------------------------------------------------------------
1 | function main() {
2 | print(sizeof());
3 |
4 | print(sizeof());
5 |
6 | print(sizeof());
7 |
8 | print("done.");
9 | }
10 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/01spread.ts:
--------------------------------------------------------------------------------
1 | function call(
2 | handler: (...args: TS) => unknown,
3 | ...args: TS): void {
4 | for (const v of args) print(v);
5 | }
6 |
7 | function main() {
8 |
9 | // Spread Parameters
10 |
11 | call((...args: number[]) => args[0] + args[1], 4, 2) // ok
12 |
13 | print("done.");
14 | }
15 |
16 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/01spread_assignment.ts:
--------------------------------------------------------------------------------
1 | function* f()
2 | {
3 | yield 1;
4 | yield 2;
5 | yield 3;
6 | }
7 |
8 | interface IData
9 | {
10 | a: number;
11 | b: string;
12 | c?: number;
13 | }
14 |
15 | class S
16 | {
17 | f = 12;
18 | d = "asd";
19 | }
20 |
21 | function main()
22 | {
23 | const v = [...f()];
24 |
25 | for (const i of v) print(i);
26 |
27 | assert (v.length == 3);
28 |
29 | let data: IData = { a: 10, b: "Hello" };
30 | let o = { ...data };
31 |
32 | print(o.a, o.b, o.c || 20);
33 |
34 | assert(o.a === 10);
35 | assert(o.b === "Hello");
36 | assert((o.c || 20) === 20);
37 |
38 | let o2 = { ...new S() };
39 |
40 | print(o2.f, o2.d);
41 |
42 | assert(o2.f === 12);
43 | assert(o2.d === "asd");
44 |
45 | print("done.");
46 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/01switch.ts:
--------------------------------------------------------------------------------
1 | function log(...data: string[]): void {
2 | printData(1, data);
3 | }
4 |
5 | function printData(fileNo: int, data: string[]): void {
6 | switch (data.length) {
7 | case 0:
8 | break;
9 | default:
10 | print1(fileNo, data[0]);
11 | for (let i = 1; i < data.length; i++) {
12 | print1(fileNo, " ");
13 | print1(fileNo, data[i]);
14 | }
15 | }
16 |
17 | print1(fileNo, "\n");
18 | }
19 |
20 | function print1(fileNo: int, data: string): void {
21 | // ...
22 | print(data);
23 | }
24 |
25 | const vf32: f32 = 12.00;
26 | const boxed3: any = vf32;
27 |
28 | log(vf32, boxed3);
29 |
30 | print("done.");
--------------------------------------------------------------------------------
/tsc/test/tester/tests/01try_catch.ts:
--------------------------------------------------------------------------------
1 | namespace exceptions {
2 |
3 | function test4(fn: () => void) {
4 | try {
5 | fn()
6 | return 10
7 | } catch {
8 | return 20
9 | }
10 | }
11 |
12 | export function run() {
13 | print("test exn")
14 |
15 | assert(test4(() => { }) == 10)
16 | assert(test4(() => { throw "foo" }) == 20)
17 |
18 | print("done.");
19 | }
20 | }
21 |
22 | function main() {
23 | exceptions.run();
24 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/01try_finally.ts:
--------------------------------------------------------------------------------
1 | // inline test
2 |
3 | function mayThrow(i: number) {
4 | if (i > 10.0)
5 | throw 1.0;
6 | }
7 |
8 | function main4() {
9 |
10 | try {
11 | print("try");
12 | mayThrow(100);
13 | }
14 | finally {
15 | print("finally");
16 | }
17 | }
18 |
19 | function main() {
20 | try {
21 | main4();
22 | }
23 | catch (e: number) {
24 | print("catch outer");
25 | }
26 |
27 | print("done.");
28 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/01types_mappedtype.ts:
--------------------------------------------------------------------------------
1 | type FeatureFlags = {
2 | darkMode: string;
3 | newUserProfile: string;
4 | };
5 |
6 | type OptionsFlags = {
7 | [Property in keyof Type]: boolean;
8 | };
9 |
10 |
11 | function f(a: A, opt: OptionsFlags)
12 | {
13 | print(a.darkMode, opt.darkMode);
14 | }
15 |
16 |
17 | function main()
18 | {
19 | let a: FeatureFlags = { darkMode: "asd1", newUserProfile: "asd2" };
20 | f(a, { darkMode: true, newUserProfile: false });
21 |
22 | print("done.");
23 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/01types_templateliteraltype.ts:
--------------------------------------------------------------------------------
1 | type Color = "red" | "green" | "blue";
2 | type HexColor = `#${string}`;
3 |
4 | // Usage:
5 | let myColor: HexColor<"blue"> = "#0000FF";
6 |
7 | assert(myColor == "#0000FF");
8 |
9 | print('done.');
--------------------------------------------------------------------------------
/tsc/test/tester/tests/02disposable.ts:
--------------------------------------------------------------------------------
1 | let count_created = 0;
2 | let count_disp = 0;
3 | function loggy(id: string) {
4 | print(`Creating ${id}`);
5 | count_created++;
6 | return {
7 | [Symbol.dispose]() {
8 | print(`Disposing ${id}`);
9 | count_disp++;
10 | }
11 | }
12 | }
13 |
14 | function func(i = 0) {
15 | using a = loggy("a");
16 | cont1: while (i-- > 0)
17 | {
18 | using b = loggy("b");
19 | let j = 3;
20 | while (j-- > 0) {
21 | using c = loggy("c");
22 | continue cont1;
23 | }
24 | }
25 |
26 | // Unreachable.
27 | // Never created, never disposed.
28 | using f = loggy("f");
29 | }
30 |
31 | function main()
32 | {
33 | func(3);
34 |
35 | assert(count_created == count_disp, "not equal create-dispose");
36 |
37 | print("done.");
38 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/02extends.ts:
--------------------------------------------------------------------------------
1 | class Base {
2 | check(prop: TProp): boolean {
3 | return true;
4 | }
5 | }
6 |
7 | class Test extends Base {
8 | m() {
9 | this.check(this);
10 | }
11 | }
12 |
13 | function main() {
14 | print("done.");
15 | }
16 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/02funcs_generic_iterator.ts:
--------------------------------------------------------------------------------
1 | type Array = T[];
2 |
3 | function ForEach(this: Array, callbackfn: (value: T, index?: number, array?: Array) => void, thisArg?: any): void
4 | {
5 | let index = 0;
6 | for (const val of this) callbackfn(val, index++, this);
7 | }
8 |
9 | function main() {
10 | [1, 2, 3].ForEach((x, y?, z?) => { print(x); });
11 | print("done.");
12 | }
13 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/02funcs_vararg.ts:
--------------------------------------------------------------------------------
1 | @varargs
2 | declare function printf(format: string);
3 |
4 | function main() {
5 | printf("Hello: %d", 10);
6 | print("done.");
7 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/02iterator.ts:
--------------------------------------------------------------------------------
1 | let run1 = false;
2 | let run2 = false;
3 | let test = true;
4 |
5 | function main() {
6 | let arr = [1, 2, 3];
7 |
8 | const it = (function* () { for (const v of arr) yield ((x: typeof v) => {run1 = true; return x + 1; })(v); })();
9 |
10 | for (const v of it) { print(v); if (v > 4 || v < 2) test = false; };
11 |
12 | const it2 = (function* () { for (const v of arr) yield ((x: T) => {run2 = true; return x + 1; })(v); })();
13 |
14 | for (const v of it2) { print(v); if (v > 4 || v < 2) test = false; };
15 |
16 | assert(run1);
17 | assert(run2);
18 | assert(test);
19 |
20 | print("done.");
21 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/02sizeof.ts:
--------------------------------------------------------------------------------
1 | function slice(start?: int, end?: int) {
2 | const v = start ? start : 0;
3 | assert(sizeof(v) != sizeof(start));
4 |
5 | const v2 = !start ? 0 : start;
6 | assert(sizeof(v2) != sizeof(start));
7 |
8 | return v;
9 | }
10 |
11 | function main() {
12 |
13 | slice();
14 | slice(10);
15 |
16 | print("done.");
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/03iterator.ts:
--------------------------------------------------------------------------------
1 | let glb1 = 0;
2 |
3 | function f3() {
4 | const syncGenerator = function* () {
5 | yield 1;
6 | yield 2;
7 | };
8 |
9 | const o = { [Symbol.iterator]: syncGenerator };
10 |
11 | for (const x of o) {
12 | print(x);
13 | glb1++;
14 | }
15 | }
16 |
17 | function main() {
18 | f3();
19 | assert(glb1 == 2);
20 | print("done.");
21 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/04union_type.ts:
--------------------------------------------------------------------------------
1 | // @strict: true
2 | interface Cat {
3 | type: 'cat';
4 | canMeow: true;
5 | }
6 |
7 | interface Dog {
8 | type: 'dog';
9 | canBark: true;
10 | }
11 |
12 | type Animal = Cat | Dog;
13 |
14 | function main() {
15 |
16 | let test = false;
17 | const animal = { type: 'dog', canBark: true } as Animal;
18 |
19 | if (animal.type == "cat") {
20 | print("this is cat, can meow? ", animal.canMeow);
21 | }
22 |
23 | if (animal.type == "dog") {
24 | test = animal.canBark;
25 | print("this is dog, can bark? ", animal.canBark);
26 | }
27 |
28 | assert(test);
29 |
30 | print("done.");
31 | }
32 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/05union_type.ts:
--------------------------------------------------------------------------------
1 | function main() {
2 | let val: string | number;
3 | val = 12
4 |
5 | assert(typeof (val) == "number")
6 |
7 | print("done.");
8 | }
9 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/08stringopertations.ts:
--------------------------------------------------------------------------------
1 | function consStringTest() {
2 | print("consStringTest");
3 | const s = "0123456789abcdef";
4 | let s0 = "";
5 | let s1 = "";
6 | for (let i = 0; i < 100; ++i) {
7 | s0 = s0 + s[i & 0xf];
8 | s1 = s[(99 - i) & 0xf] + s1;
9 | }
10 | assert(s0 == s1, "c0");
11 | assert(s0.length == 100, "c1");
12 | }
13 |
14 | function testStringOps(): void {
15 | //assert("foo".concat("bar") == "foobar", "concat");
16 | //assert("xAb".charCodeAt(1) == 65, "code at");
17 | //assert("B".charCodeAt(0) == 66, "tcc");
18 | assert(parseInt("-123") == -123, "tonum");
19 | assert("fo"[1] == "o", "at");
20 | assert("fo".length == 2, "count");
21 | //assert(!"fo".charCodeAt(17), "nan");
22 | }
23 |
24 | function main() {
25 | testStringOps();
26 | consStringTest();
27 | print("done.");
28 | }
29 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/09postprefix.ts:
--------------------------------------------------------------------------------
1 | let lazyAcc: number;
2 |
3 | class Testrec {
4 | str: string;
5 | num: number;
6 | bool: boolean;
7 | str2: string;
8 | }
9 |
10 | function recordId(x: Testrec) {
11 | lazyAcc++;
12 | return x;
13 | }
14 |
15 | function postPreFix() {
16 | print("postPref");
17 | let x = new Testrec();
18 | lazyAcc = 0;
19 | recordId(x).num = 12;
20 | assert(x.num == 12 && lazyAcc == 1, "X0-");
21 | let y = recordId(x).num++;
22 | assert(x.num == 13 && lazyAcc == 2, "X1");
23 | assert(y == 12, "X2");
24 | y = ++recordId(x).num;
25 | assert(y == 14 && x.num == 14 && lazyAcc == 3, "X2");
26 |
27 | recordId(x).num >>= 1;
28 | assert(x.num == 7, "X3");
29 | assert(lazyAcc == 4, "X4");
30 | lazyAcc = 0;
31 | }
32 |
33 | function main() {
34 | postPreFix();
35 | print("done.");
36 | }
37 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/10arrayincrement.ts:
--------------------------------------------------------------------------------
1 | let glb1 = 0;
2 |
3 | function testArrIncr() {
4 | let arr = [1];
5 | glb1 = 0;
6 | function getarr() {
7 | glb1++;
8 | return arr;
9 | }
10 | getarr()[0]++;
11 | assert(glb1 == 1);
12 | assert(arr[0] == 2, "t");
13 | function getarr2() {
14 | return [1];
15 | }
16 | getarr2()[0]++; // make sure it doesn't crash
17 | }
18 |
19 | function main() {
20 | testArrIncr();
21 | print("done.");
22 | }
23 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/12referencecollection.ts:
--------------------------------------------------------------------------------
1 | // @strict-null false
2 | class Testrec {
3 | str: string;
4 | num: number;
5 | bool: boolean;
6 | str2: string;
7 | }
8 |
9 | function testRec0(): Testrec {
10 | let testrec = new Testrec();
11 | testrec.str2 = "Hello" + " world";
12 | testrec.str = testrec.str2;
13 | testrec.num = 42;
14 | assert(testrec.str == "Hello world", "recstr");
15 | assert(testrec.num == 42, "recnum");
16 | print(testrec.str2);
17 | let testrec2 = null;
18 | assert(testrec2 == null, "isinv");
19 | assert(testrec == testrec, "eq");
20 | assert(testrec != null, "non inv");
21 | return testrec;
22 | }
23 |
24 | function testReccoll(): void {
25 | let coll: Testrec[] = [];
26 | let item = testRec0();
27 | print("in reccoll");
28 | coll.push(item);
29 | }
30 |
31 | function main() {
32 | testReccoll();
33 | print("done.");
34 | }
35 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/19forof_capture.ts:
--------------------------------------------------------------------------------
1 | let glb1 = 0;
2 |
3 | type func = () => void;
4 |
5 | function testForOf() {
6 | let f = [];
7 | glb1 = 0;
8 | for (const q of [1, 12]) {
9 | f.push((() => {
10 | glb1 += q;
11 | }));
12 | }
13 |
14 | print("calling...");
15 |
16 | (f[0])();
17 | (f[1])();
18 | assert(glb1 == 13, "foc");
19 | }
20 |
21 | function main() {
22 | testForOf();
23 | print("done.");
24 | }
25 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/23generics.ts:
--------------------------------------------------------------------------------
1 | // @strict-null false
2 | // TODO: not finished - testGenRef is not compiled (ignored)
3 | function testGenRef(v: T) {
4 | let x = v
5 | // test that clear() also gets generalized
6 | function clear() {
7 | x = null
8 | }
9 | clear()
10 | }
11 |
12 | function testGenRefOuter() {
13 | print("testGenRefOuter");
14 | testGenRef(12)
15 | testGenRef("fXa" + "baa")
16 | }
17 |
18 | function main()
19 | {
20 | testGenRefOuter()
21 | print("done.")
22 | }
23 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/241arrayforeach.ts:
--------------------------------------------------------------------------------
1 | function main() {
2 | print("testArrayFoEach");
3 | let strs: string[] = [];
4 | [1, 2, 3].forEach(x => strs.push("X" + x))
5 | let r = "A"
6 | for (let s of strs) {
7 | r += s
8 | }
9 | assert(r == "AX1X2X3", "forEach")
10 | print("done.");
11 | }
12 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/243arrayevery.ts:
--------------------------------------------------------------------------------
1 | function main() {
2 | let str = [1, 2, 3];
3 | assert(!str.every(x => x == 2), "everyfalse");
4 | assert(str.every(x => x > 0), "everytrue");
5 | print("done.");
6 | }
7 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/244arraysome.ts:
--------------------------------------------------------------------------------
1 | function main() {
2 | let str = [1.0, 2.0, 3.0];
3 | assert(str.some(x => x == 2), "sometrue");
4 | assert(!str.some(x => x < 0), "somefalse");
5 | print("done.");
6 | }
7 |
8 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/25lamdacapture.ts:
--------------------------------------------------------------------------------
1 | let glb1 = 0;
2 |
3 | function testInnerLambdaCapture() {
4 | print("testInnerLambdaCapture");
5 | glb1 = 0;
6 | let a = 7;
7 | let g = () => {
8 | let h = () => {
9 | glb1 += a;
10 | };
11 | h();
12 | };
13 | g();
14 | assert(glb1 == 7, "7");
15 | }
16 |
17 | function main() {
18 | testInnerLambdaCapture();
19 | print("done.");
20 | }
21 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/26staticclasses.ts:
--------------------------------------------------------------------------------
1 | let glb1 = 0;
2 |
3 | class StaticCl {
4 | static x = 12;
5 | static foo() {
6 | glb1 += StaticCl.x;
7 | }
8 | static bar(k: number) {
9 | StaticCl.x = k;
10 | }
11 |
12 | static doSomething: (v: number) => void;
13 | }
14 |
15 | function testStatic() {
16 | print("testStatic");
17 | glb1 = 0;
18 | StaticCl.foo();
19 | assert(glb1 == 12, "s0");
20 | StaticCl.bar(13);
21 | StaticCl.foo();
22 | assert(glb1 == 25, "s1");
23 |
24 | StaticCl.doSomething = (x) => {
25 | assert(x == 42, "s42");
26 | };
27 | StaticCl.doSomething(42);
28 | }
29 |
30 | function main() {
31 | testStatic();
32 | print("done.");
33 | }
34 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/28boolcasts.ts:
--------------------------------------------------------------------------------
1 | // @strict-null false
2 | class BazClass {}
3 | function testBoolCasts() {
4 | print("testBoolCast");
5 | function boolDie() {
6 | assert(false, "bool casts");
7 | }
8 | let x = "Xy" + "Z";
9 |
10 | if (x) {
11 | } else {
12 | boolDie();
13 | }
14 |
15 | // TODO: finish it
16 | /*
17 | if ("") {
18 | boolDie()
19 | }
20 | */
21 |
22 | let v = new BazClass();
23 | if (v) {
24 | } else {
25 | boolDie();
26 | }
27 | if (!v) {
28 | boolDie();
29 | }
30 | v = null;
31 | if (v) {
32 | boolDie();
33 | }
34 | if (!v) {
35 | } else {
36 | boolDie();
37 | }
38 | }
39 |
40 | function main() {
41 | testBoolCasts();
42 | print("done.");
43 | }
44 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/35lambdaparameters.ts:
--------------------------------------------------------------------------------
1 | function testLambdasWithMoreParams() {
2 | function a(f: (x: number, v: string, y: number) => void) {
3 | f(1, "a" + "X12b", 7);
4 | }
5 | a((x: number, v: string, y: number) => {});
6 | }
7 |
8 | namespace Arcade1617 {
9 | class Foo {
10 | public handlerxx: (win?: boolean) => void;
11 | run() {
12 | this.handlerxx();
13 | }
14 | }
15 |
16 | function end(win?: boolean) {
17 | assert(win === undefined, "lp1");
18 | }
19 |
20 | function test() {
21 | const f = new Foo();
22 | f.handlerxx = end;
23 | f.run();
24 | }
25 | }
26 |
27 | function main() {
28 | testLambdasWithMoreParams();
29 | Arcade1617.test();
30 | print("done.");
31 | }
32 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/43nestednamespace.ts:
--------------------------------------------------------------------------------
1 | let glb1 = 0;
2 |
3 | namespace fooX.bar.baz {
4 | export class A {
5 | foo() {
6 | glb1++;
7 | }
8 | }
9 | export function b() {
10 | glb1++;
11 | glb1++;
12 | }
13 | }
14 |
15 | import bz = fooX.bar.baz;
16 | import AA = fooX.bar.baz.A;
17 | function testImports() {
18 | glb1 = 0;
19 | bz.b();
20 | let x = new AA();
21 | x.foo();
22 | assert(glb1 == 3, "imports");
23 | }
24 |
25 | function main() {
26 | testImports();
27 | print("done.");
28 | }
29 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/45enumtostring.ts:
--------------------------------------------------------------------------------
1 | function getABoolean() {
2 | return !!true;
3 | }
4 |
5 | enum SomeEnum {
6 | One = 1,
7 | Two = 2,
8 | }
9 |
10 | function main() {
11 | print("test enum to string");
12 |
13 | let enumTest = getABoolean() ? SomeEnum.One : SomeEnum.Two;
14 |
15 | assert(`${enumTest}` === "1", "enum tostring in template");
16 | assert(enumTest + "" === "1", "enum tostring in concatenation");
17 |
18 | print("done.");
19 | }
20 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/additionOperatorWithNumberAndEnum.ts:
--------------------------------------------------------------------------------
1 | function main() {
2 |
3 | enum E { a, b }
4 | enum F { c, d }
5 |
6 | let a: number;
7 | let b: E;
8 | let c: E | F;
9 |
10 | let r1 = a + a;
11 | let r2 = a + b;
12 | let r3 = b + a;
13 | let r4 = b + b;
14 |
15 | let r5 = 0 + a;
16 | let r6 = E.a + 0;
17 | let r7 = E.a + E.b;
18 | let r8 = E['a'] + E['b'];
19 | let r9 = E['a'] + F['c'];
20 |
21 | let r10 = a + c;
22 | // TODO: should I allow to store number into integer?
23 | //let r11 = c + a;
24 | let r12 = b + c;
25 | let r13 = c + b;
26 | let r14 = c + c;
27 |
28 | print("done.");
29 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/arrayFakeFlatNoCrashInferenceDeclarations.ts:
--------------------------------------------------------------------------------
1 | // @strict: true
2 | // @lib: es2020
3 | // @declaration: true
4 | type BadFlatArray = {obj: {
5 | "done": Arr,
6 | "recur": Arr extends ReadonlyArray
7 | ? BadFlatArray
8 | : Arr
9 | }[Depth extends -1 ? "done" : "recur"]}["obj"];
10 |
11 | declare function flat(
12 | arr: A,
13 | depth?: D
14 | ): BadFlatArray[]
15 |
16 | function foo(arr: T[], depth: number) {
17 | return flat(arr, depth);
18 | }
19 |
20 | function main()
21 | {
22 | print('done.');
23 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/assignmentTypeNarrowing.ts:
--------------------------------------------------------------------------------
1 | function main() {
2 | let x: string | number | boolean;
3 |
4 | x = "";
5 | x; // string
6 |
7 | [x] = [true];
8 | x; // boolean
9 |
10 | [x = ""] = [1];
11 | x; // string | number
12 |
13 | ({ x } = { x: true });
14 | x; // boolean
15 |
16 | ({ y: x } = { y: 1 });
17 | x; // number
18 |
19 | ({ x = "" } = { x: true });
20 | x; // string | boolean
21 |
22 | let a: string[] = [];
23 |
24 | for (x of a) {
25 | x; // string
26 | }
27 |
28 | print("done.");
29 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/component.ts:
--------------------------------------------------------------------------------
1 | import Service from "./service";
2 |
3 | class MyComponent {
4 | constructor(public Service: Service) {
5 | }
6 |
7 | method(x: this) {
8 | }
9 | }
10 |
11 | function main()
12 | {
13 | const myComponent = new MyComponent(new Service());
14 | print("done.");
15 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/decl_class.ts:
--------------------------------------------------------------------------------
1 | export class Account
2 | {
3 | public static data = 10;
4 |
5 | constructor(public n = 0)
6 | {
7 | print("account - ctor: ", n);
8 | this.data = n;
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/decl_enum.ts:
--------------------------------------------------------------------------------
1 | export enum PointTest { Invalid, Valid };
2 | export function pointTest (x: number, y: number): PointTest {
3 | return PointTest.Valid;
4 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/decl_interface.ts:
--------------------------------------------------------------------------------
1 | export interface Point { x: number; y: number; };
2 | export function point (x: number, y: number): Point {
3 | return { x: x, y: y };
4 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/decl_type.ts:
--------------------------------------------------------------------------------
1 | export type Point = { x: number; y: number; };
2 | export function point (x: number, y: number): Point {
3 | return { x: x, y: y };
4 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/declare_global_var.ts:
--------------------------------------------------------------------------------
1 | declare static class Math {
2 | /** Pi. This is the ratio of the circumference of a circle to its diameter. */
3 | readonly PI: number;
4 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/define_global_var.ts:
--------------------------------------------------------------------------------
1 | export static class Math {
2 | /** Pi. This is the ratio of the circumference of a circle to its diameter. */
3 | public PI = 3.141592653589793;
4 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/dependencies.ts:
--------------------------------------------------------------------------------
1 | class FileSystemObject {
2 | isFile(): this is File {
3 | return this instanceof File;
4 | }
5 | isDirectory(): this is Directory {
6 | return this instanceof Directory;
7 | }
8 | constructor(public path: string, private networked: boolean) { }
9 | }
10 |
11 | class File extends FileSystemObject {
12 | constructor(path: string, public content: string) {
13 | super(path, false);
14 | }
15 | }
16 |
17 | class Directory extends FileSystemObject {
18 | children: FileSystemObject[];
19 | }
20 |
21 | function main() {
22 |
23 | let fso: FileSystemObject = new File("foo/bar.txt", "foo");
24 | if (fso.isFile()) {
25 | print("fso is File");
26 | } else if (fso.isDirectory()) {
27 | print("fso is Directory");
28 | }
29 |
30 | print("done.");
31 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/emitDefaultParametersFunctionExpression.ts:
--------------------------------------------------------------------------------
1 | function main() {
2 |
3 | let lambda1 = (y = "hello") => { }
4 | let lambda2 = (x: number, y = "hello") => { }
5 | let lambda3 = (x: number, y = "hello", ...rest: any[]) => { }
6 | let lambda4 = (y = "hello", ...rest: any[]) => { }
7 |
8 | let x = function (str = "hello", ...rest: any[]) { }
9 | let y = (function (num = 10, boo = false, ...rest: any[]) { })()
10 | let z = (function (num: number, boo = false, ...rest: any[]) { })(10)
11 |
12 | print("done.");
13 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/emit_class.ts:
--------------------------------------------------------------------------------
1 | @dynamic
2 | import './decl_class';
3 |
4 | function main() {
5 | const a1 = new Account();
6 | print(a1.n);
7 |
8 | const a2 = new Account(2);
9 | print(a2.n);
10 |
11 | print(Account.data);
12 |
13 | assert(Account.data == 2);
14 |
15 | print(a2 instanceof Account);
16 |
17 | assert(a2 instanceof Account);
18 |
19 | print("done.");
20 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/emit_compiletime_class.ts:
--------------------------------------------------------------------------------
1 | @dllimport
2 | declare class Account
3 | {
4 | public n?: TypeOf<1>;
5 |
6 | constructor(n?: TypeOf<1>);
7 | }
8 |
9 | function main()
10 | {
11 | const a1 = new Account();
12 | print(a1.n);
13 |
14 | const a2 = new Account(2);
15 | print(a2.n);
16 |
17 | print("done.");
18 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/emit_compiletime_func.ts:
--------------------------------------------------------------------------------
1 | type Point = { x: number; y: number; };
2 |
3 | @dllimport
4 | declare function point (x: number, y: number): Point;
5 |
6 | function main() {
7 | const p = point (1.0, 2.0);
8 | print(`x=${p.x}, y=${p.y}`);
9 |
10 | print("done.");
11 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/emit_enum.ts:
--------------------------------------------------------------------------------
1 | import "./decl_enum";
2 |
3 | function main()
4 | {
5 | const p = pointTest (1.0, 2.0);
6 | if (p == PointTest.Valid)
7 | print(`Valid`)
8 | if (p == PointTest.Invalid)
9 | print(`Invalid`)
10 |
11 | print("done.");
12 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/emit_interface.ts:
--------------------------------------------------------------------------------
1 | import "./decl_interface";
2 |
3 | function main()
4 | {
5 | const p = point (1.0, 2.0);
6 | print(`x=${p.x}, y=${p.y}`);
7 | print("done.");
8 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/emit_type.ts:
--------------------------------------------------------------------------------
1 | import "./decl_type";
2 |
3 | function main()
4 | {
5 | const p = point (1.0, 2.0);
6 | print(`x=${p.x}, y=${p.y}`);
7 | print("done.");
8 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/export_class_interface.ts:
--------------------------------------------------------------------------------
1 | namespace A {
2 |
3 | interface Point {
4 | x: number;
5 | y: number;
6 |
7 | fromOrigin(p: Point): number;
8 | }
9 |
10 | export class Point2d implements Point {
11 | constructor(public x: number, public y: number) { }
12 |
13 | fromOrigin(p: Point) {
14 | return this.x + this.y + p.x + p.y + p.fromOrigin(this);
15 | }
16 | }
17 | }
18 |
19 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/export_enum.ts:
--------------------------------------------------------------------------------
1 | namespace A
2 | {
3 | enum Enum1
4 | {
5 | A1,
6 | B1
7 | }
8 | }
9 |
10 | namespace B
11 | {
12 | export function f(): A.Enum1
13 | {
14 | return A.Enum1.A1;
15 | }
16 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/export_object_literal_with_class_types.ts:
--------------------------------------------------------------------------------
1 | namespace A {
2 |
3 | class Point {
4 | constructor(public x: number, public y: number) { }
5 | }
6 |
7 | export var UnitSquare : {
8 | top: { left: Point, right: Point },
9 | bottom: { left: Point, right: Point }
10 | } = { top: { left: null, right: null }, bottom: { left: null, right: null } };
11 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/export_object_literal_with_interface.ts:
--------------------------------------------------------------------------------
1 | namespace A {
2 |
3 | export interface Point {
4 | x: number;
5 | y: number;
6 | }
7 |
8 | // valid since Point is exported
9 | export var Origin: Point = { x: 0, y: 0 };
10 |
11 | interface Point3d extends Point {
12 | z: number;
13 | }
14 |
15 | // invalid Point3d is not exported
16 | export var Origin3d: Point3d = { x: 0, y: 0, z: 0 };
17 | }
18 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/export_vars.ts:
--------------------------------------------------------------------------------
1 |
2 | namespace Inner {
3 | export var a;
4 | export let b;
5 | export var c: string;
6 | export let d: number;
7 | class A {}
8 | export var e: A;
9 | export let f: A;
10 |
11 | namespace B {
12 | export let a = 1, b, c = 2;
13 | export let x, y, z;
14 | }
15 |
16 | namespace C {
17 | export var a = 1, b, c = 2;
18 | export var x, y, z;
19 | }
20 |
21 | // Shouldn't be filtered
22 | export var a1 = 1;
23 | export let b1 = 1;
24 | export var c1: string = 'a';
25 | export let d1: number = 1;
26 | // TODO: finish loading GCtors from DLL
27 | //class D {}
28 | //export var e1 = new D;
29 | //export let f1 = new D;
30 | //export var g1: D = new D;
31 | //export let h1: D = new D;
32 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/export_vars2.ts:
--------------------------------------------------------------------------------
1 | namespace Inner {
2 | class D {}
3 | export var e1 = new D;
4 | export let f1 = new D;
5 | export var g1: D = new D;
6 | export let h1: D = new D;
7 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/import_class_interface.ts:
--------------------------------------------------------------------------------
1 | import './export_class_interface'
2 |
3 | const p = new A.Point2d(10, 20);
4 | const v =
5 | p.fromOrigin({
6 | x:100,
7 | y:200,
8 | fromOrigin(p: A.Point) { return p.x * p.y + this.x + this.y; }
9 | });
10 |
11 | print(v);
12 |
13 | assert(v == 830.0);
14 |
15 | print("done.");
16 |
17 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/import_enum.ts:
--------------------------------------------------------------------------------
1 | import './export_enum'
2 |
3 | const en = B.f();
4 |
5 | print(en, A.Enum1.B1);
6 |
7 | assert(en == A.Enum1.A1)
8 |
9 | print("done.");
--------------------------------------------------------------------------------
/tsc/test/tester/tests/import_object_literal_with_class_types.ts:
--------------------------------------------------------------------------------
1 | import './export_object_literal_with_class_types'
2 |
3 | assert(A.UnitSquare.bottom.left == null);
4 |
5 | if (A.UnitSquare.bottom.left == null)
6 | {
7 | print("null");
8 | }
9 |
10 | print("done.");
11 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/import_object_literal_with_interface.ts:
--------------------------------------------------------------------------------
1 | import './export_object_literal_with_interface'
2 |
3 | if (A.Origin.x == 0)
4 | {
5 | print("ok");
6 | }
7 |
8 | if (A.Origin3d.x == 0)
9 | {
10 | print("ok");
11 | }
12 |
13 | print("done.");
14 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/import_vars.ts:
--------------------------------------------------------------------------------
1 | import './export_vars'
2 |
3 | print(Inner.d);
4 |
5 | print("done.");
--------------------------------------------------------------------------------
/tsc/test/tester/tests/import_vars2.ts:
--------------------------------------------------------------------------------
1 | import './export_vars2'
2 |
3 | print(Inner.e1 != null);
4 |
5 | print("done.");
--------------------------------------------------------------------------------
/tsc/test/tester/tests/include_global_var.ts:
--------------------------------------------------------------------------------
1 | ///
2 |
3 | assert(Math.PI === 3.141592653589793);
4 |
5 | print("done.");
--------------------------------------------------------------------------------
/tsc/test/tester/tests/load_store_decorators.ts:
--------------------------------------------------------------------------------
1 | enum MemoryOrder {
2 | NotAtomic = 0,
3 | Unordered = 1,
4 | Monotonic = 2,
5 | Acquire = 4,
6 | Release = 5,
7 | AcquireRelease = 6,
8 | SequentiallyConsistent = 7,
9 | }
10 |
11 | // load - acquire, store - release
12 | @atomic(MemoryOrder.Acquire, "test")
13 | @volatile
14 | @nontemporal
15 | @invariant
16 | let a = 1;
17 | a = 2;
18 | print(a);
19 |
20 | @atomic(MemoryOrder.AcquireRelease, "test")
21 | @volatile
22 | @nontemporal
23 | @invariant
24 | let b = 3;
25 | b = 4;
26 | print(b);
27 |
28 | @atomic(MemoryOrder.SequentiallyConsistent, "test")
29 | @volatile
30 | @nontemporal
31 | @invariant
32 | let c = 5;
33 | c = 6;
34 | print(c);
35 |
36 | print("done.");
--------------------------------------------------------------------------------
/tsc/test/tester/tests/logicalAssignment5_2.ts:
--------------------------------------------------------------------------------
1 | function foo1 (f?: (a: number) => number) {
2 | f ??= ((a: number) => (assert(a == 42), a))
3 | f(42)
4 | }
5 |
6 | function foo2 (f?: (a: number) => number) {
7 | f ||= ((a: number) => (assert(a == 42), a))
8 | f(42)
9 | }
10 |
11 | function foo3 (f?: (a: number) => number) {
12 | f &&= ((a: number) => (assert(a == 42), a))
13 | f(42)
14 | }
15 |
16 | function bar1 (f?: (a: number) => number) {
17 | f ??= (f, (a => (assert(a == 42), a)))
18 | f(42)
19 | }
20 |
21 | function bar2 (f?: (a: number) => number) {
22 | f ||= (f, (a => (assert(a == 42), a)))
23 | f(42)
24 | }
25 |
26 | function bar3 (f?: (a: number) => number) {
27 | f &&= (f, (a => (assert(a == 42), a)))
28 | f(42)
29 | }
30 |
31 | function main() {
32 | foo1();
33 | foo2();
34 | foo3();
35 |
36 | bar1();
37 | bar2();
38 | bar3();
39 |
40 | print("done.");
41 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/logicalAssignment5_3.ts:
--------------------------------------------------------------------------------
1 | function foo1(f?: (a: number) => number) {
2 | f ??= ((a) => a)
3 | assert(f(42) == 42);
4 | }
5 |
6 | function foo2(f?: (a: number) => number) {
7 | f ||= ((a) => a)
8 | assert(f(42) == 42);
9 | }
10 |
11 | function foo3(f?: (a: number) => number) {
12 | f &&= ((a) => a)
13 | assert(f(42) == 42);
14 | }
15 |
16 | function bar1(f?: (a: number) => number) {
17 | f ??= (f, ((a) => a))
18 | assert(f(42) == 42);
19 | }
20 |
21 | function bar2(f?: (a: number) => number) {
22 | f ||= (f, ((a) => a))
23 | assert(f(42) == 42);
24 | }
25 |
26 | function bar3(f?: (a: number) => number) {
27 | f &&= (f, ((a) => a))
28 | assert(f(42) == 42);
29 | }
30 |
31 | function main() {
32 |
33 | foo1();
34 | foo2();
35 | foo3((a) => a * 2);
36 |
37 | bar1();
38 | bar2();
39 | bar3((a) => a * 2);
40 |
41 | print("done.");
42 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/no_main.ts:
--------------------------------------------------------------------------------
1 | const arr = [1, 2, 3, 4, 5];
2 |
3 | let a = 10;
4 |
5 | a += 20;
6 |
7 | const b = a;
8 |
9 | print(a, b);
10 |
11 | for (const b of arr)
12 | print(b);
13 |
14 | assert(arr.length == 5);
15 | assert(a == b);
16 | assert(a == 30);
17 |
18 | print("done.");
--------------------------------------------------------------------------------
/tsc/test/tester/tests/service.ts:
--------------------------------------------------------------------------------
1 | export class Service {
2 | }
3 |
--------------------------------------------------------------------------------
/tsc/test/tester/tests/shared.ts:
--------------------------------------------------------------------------------
1 | export const val_num = 2.5;
2 | export const val_str = "Hello World! - val";
3 |
4 | export function test1()
5 | {
6 | print("Hello World! test 1");
7 | }
8 |
9 | export function test2()
10 | {
11 | print("Hello World! test 2");
12 | }
--------------------------------------------------------------------------------
/tsc/test/tester/tests/use_shared.ts:
--------------------------------------------------------------------------------
1 | import './shared'
2 |
3 | function main()
4 | {
5 | test1();
6 | test2();
7 |
8 | print(val_str);
9 |
10 | print(val_num);
11 |
12 | print("done.");
13 | }
--------------------------------------------------------------------------------
/tsc/tsc-new-parser/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "cmake.configureOnOpen": false
3 | }
--------------------------------------------------------------------------------
/tsc/tsc-new-parser/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | set_Options_With_FS()
2 |
3 | add_library(tsc-new-parser-lib parser.cpp node_factory.cpp parenthesizer_rules.cpp scanner.cpp)
4 |
5 | add_executable(tsc-new-scanner scanner_run.cpp scanner.cpp)
6 |
7 | target_link_libraries(tsc-new-scanner PRIVATE ${LIBS})
8 |
9 | add_executable(tsc-new-parser parser_run.cpp parser.cpp node_factory.cpp parenthesizer_rules.cpp scanner.cpp)
10 |
11 | target_link_libraries(tsc-new-parser PRIVATE ${LIBS})
12 |
13 |
--------------------------------------------------------------------------------
/tsc/tsc-new-parser/parser_jdoc.h:
--------------------------------------------------------------------------------
1 | #ifndef PARSER_JDOC_H
2 | #define PARSER_JDOC_H
3 |
4 | #include "config.h"
5 | #include "parser.h"
6 |
7 | struct EntityNameWIthBracketed
8 | {
9 | EntityNameWIthBracketed() = default;
10 | EntityName name;
11 | boolean isBracketed;
12 | };
13 |
14 | #endif // PARSER_JDOC_H
--------------------------------------------------------------------------------
/tsc/tsc-new-parser/undefined.h:
--------------------------------------------------------------------------------
1 | #ifndef UNDEFINED_H
2 | #define UNDEFINED_H
3 |
4 | #include "config.h"
5 |
6 | struct undefined_t
7 | {
8 | constexpr operator number()
9 | {
10 | return -1;
11 | }
12 | };
13 |
14 | static undefined_t undefined;
15 |
16 |
17 | #endif // UNDEFINED_H
--------------------------------------------------------------------------------
/tsc/tsc/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "cmake.configureOnOpen": false
3 | }
--------------------------------------------------------------------------------
/tsc/unittests/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "cmake.configureOnOpen": false
3 | }
--------------------------------------------------------------------------------
/tsc/unittests/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | message(STATUS ">>> unittests >>> TypeScript Unit Tests")
2 |
3 | set_target_properties(MLIRTypeScriptUnitTests PROPERTIES FOLDER "TypeScript Unit Tests")
4 |
5 | add_dependencies(MLIRTypeScriptUnitTests MLIRTypeScript)
6 |
7 | function(add_mlir_unittest test_dirname)
8 | add_unittest(MLIRTypeScriptUnitTests ${test_dirname} ${ARGN})
9 | message(STATUS ">>> unittests >>> added ${test_dirname}")
10 |
11 | # add_custom_command(
12 | # TARGET ${test_dirname} POST_BUILD
13 | # COMMAND "$"
14 | # VERBATIM)
15 |
16 | add_test(NAME unittest-${test_dirname} COMMAND "$")
17 |
18 | endfunction()
19 |
20 | set_Options()
21 |
22 | add_subdirectory(Example)
23 | add_subdirectory(MLIRGen)
24 |
--------------------------------------------------------------------------------
/tsc/unittests/Example/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | add_mlir_unittest(MLIRExampleTests
2 | Example.cpp
3 | )
4 | get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
5 |
6 | target_link_libraries(MLIRExampleTests
7 | PRIVATE
8 | #MLIRArithToLLVM
9 | ${dialect_libs}
10 |
11 | )
12 |
--------------------------------------------------------------------------------
/tsc/unittests/Example/Example.cpp:
--------------------------------------------------------------------------------
1 | #include "gmock/gmock.h"
2 |
3 | TEST(Example, example1) {
4 | EXPECT_THAT(1, 1);
5 | }
6 |
--------------------------------------------------------------------------------
/tsc/unittests/MLIRGen/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | add_mlir_unittest(MLIRGenTests
2 | TypeToString.cpp
3 | )
4 | get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
5 |
6 | target_include_directories(MLIRGenTests
7 | PRIVATE
8 | ${PROJECT_SOURCE_DIR}/tsc-new-parser
9 | )
10 |
11 | target_link_libraries(MLIRGenTests
12 | PRIVATE
13 | ${dialect_libs}
14 | MLIRTypeScript
15 | )
16 |
--------------------------------------------------------------------------------