• Stars
    star
    893
  • Rank 49,019 (Top 1.0 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 8 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Tsickle β€” TypeScript to Closure Translator

Tsickle - TypeScript to Closure Translator Build Status

Tsickle converts TypeScript code into a form acceptable to the Closure Compiler. This allows using TypeScript to transpile your sources, and then using Closure Compiler to bundle and optimize them, while taking advantage of type information in Closure Compiler.

What conversion means

A (non-exhaustive) list of the sorts of transformations Tsickle applies:

  • inserts Closure-compatible JSDoc annotations on functions/classes/etc
  • converts ES6 modules into goog.module modules
  • generates externs.js from TypeScript d.ts (and declare, see below)
  • declares types for class member variables
  • translates export * from ... into a form Closure accepts
  • converts TypeScript enums into a form Closure accepts
  • reprocesses all jsdoc to strip Closure-invalid tags

In general the goal is that you write valid TypeScript and Tsickle handles making it valid Closure Compiler code.

Warning: unsupported

Google uses tsickle internally to minify its apps (including those using Angular) using Closure Compiler. We have little experience using tsickle in the other JavaScript ecosystems that are seen outside of Google, and there is generally no support for using it from our side.

Usage

Tsickle is a library, designed to be used by a larger program that interacts with TypeScript and the Closure compiler.

Some known clients are:

  1. Within Google we use tsickle inside the Bazel build system. That code is published as open source as part of Bazel's nodejs/TypeScript build rules.
  2. tscc wraps tsickle and closure compiler, and interops with rollup.
  3. We publish a simple demo program in the demo/ subdirectory.

Design details

Output format

Tsickle is designed to do whatever is necessary to make the code acceptable by Closure compiler. We view its output as a necessary intermediate form for communicating to the Closure compiler, and not something for humans. This means the tsickle output may be kind of ugly to read. Its only real use is to pass it on to the compiler.

For one example, the syntax of types tsickle produces are specific to Closure. The type {!Foo} means "Foo, excluding null" and a type alias becomes a var statement that is tagged with @typedef.

Tsickle emits modules using Closure's goog.module module system. This system is similar to but different from ES modules, and was supported by Closure before the ES module system was finalized.

Differences from TypeScript

Closure and TypeScript are not identical. Tsickle hides most of the differences, but users must still be aware of some differences.

declare

Any declaration in a .d.ts file, as well as any declaration tagged with declare ..., is intepreted by Tsickle as a name that should be preserved through Closure compilation (i.e. not renamed into something shorter). Use it any time the specific string names of your fields are significant. That would most often happen when the object either coming from outside your program, or being passed out of the program.

Example:

declare interface JSONResult {
    username: string;
}
let r = JSON.parse(input) as JSONResult;
console.log(r.username);

By adding declare to the interface (or if it were in a .d.ts file), Tsickle will inform Closure that it must use exactly the field name .username (and not e.g. .a) in the output JS. This matters for this example because the input JSON probably uses the string 'username' and not whatever name Closure would invent for it. (Note: declare on an interface has no additional meaning in pure TypeScript.)

Exporting decorators

An exporting decorator is a decorator that has @ExportDecoratedItems in its JSDoc.

The names of elements that have an exporting decorator are preserved through the Closure compilation process by applying an @export tag to them.

Example:

/** @ExportDecoratedItems */
function myDecorator() {
  // ...
}

@myDecorator()
class DoNotRenameThisClass { ... }

Development

Dependencies

One-time setup

Run yarn to install dependencies.

Build & Test commands

  • yarn build builds the code base.
  • Run tsc --watch for an interactive, incremental, and continuous build.
  • yarn lint checks for lint.
  • yarn test runs unit tests, e2e tests and checks for lint (but make sure to yarn build first or run tsc!). Set the TESTBRIDGE_TEST_ONLY environment variable to filter what golden tests to run.

TypeScript AST help

https://astexplorer.net/ and https://ts-ast-viewer.com/ are convenient tools to visualize and inspect a TypeScript AST.

Debugging

You can debug tests by passing --node_options=--inspect or --node_options=--inspect-brk (to suspend execution directly after startup).

For example, to debug a specific golden test:

TESTBRIDGE_TEST_ONLY=my_golden_test node --inspect-brk=4332 ./node_modules/.bin/jasmine out/test/*.js

Then open [about:inspect] in Chrome and choose "about:inspect". Chrome will launch a debugging session on any node process that starts with a debugger listening on one of the listed ports. The tsickle tests and Chrome both default to localhost:9229, so things should work out of the box.

The break in specific code locations you can add debugger; statements in the source code.

Updating Goldens

Run UPDATE_GOLDENS=y yarn test to have the test suite update the goldens in test_files/....

Environment variables

Set the environment variable TESTBRIDGE_TEST_ONLY=<REGEX> to limit the golden tests (found in test_files/...) to only run tests with a name matching the regex.

Releasing

On a new branch, run:

# tsickle releases are all minor releases for now, see npm help version.
$ npm version minor

This will update the version in package.json, commit the changes, and create a git tag.

Push the branch, open a pull request, get it reviewed, and wait for it to be merged.

Checkout and pull the latest version from master:

$ git checkout master && git pull

Check if the tag exists. If not, re-tag the commit and push the tag.

$ git tag
# Does this show the tag already? If not, proceed with:
$ git tag v0.32.0 && git push origin v0.32.0  # but use correct version

Once the versioned tag is pushed to GitHub the release (as found on https://github.com/angular/tsickle/releases) will be implicitly created.

From the master branch run:

npm config set registry https://wombat-dressing-room.appspot.com
npm login
npm publish  # runs a clean build & test automatically

More Repositories

1

angular

The modern web developer’s platform
TypeScript
91,840
star
2

angular.js

AngularJS - HTML enhanced for web apps!
JavaScript
59,091
star
3

angular-cli

CLI tool for Angular
TypeScript
26,587
star
4

components

Component infrastructure and Material Design components for Angular
TypeScript
24,075
star
5

material

Material design for AngularJS
JavaScript
16,637
star
6

angular-seed

Seed project for angular apps.
JavaScript
13,050
star
7

protractor

E2E test framework for Angular apps
JavaScript
8,780
star
8

angularfire

Angular + Firebase = ❀️
TypeScript
7,595
star
9

flex-layout

Provides HTML UI layout for Angular applications; using Flexbox and a Responsive API
TypeScript
5,911
star
10

universal

Server-side rendering and Prerendering for Angular
TypeScript
4,029
star
11

zone.js

Implements Zones for JavaScript
TypeScript
3,243
star
12

quickstart

Angular QuickStart - source from the documentation
JavaScript
3,128
star
13

angular-phonecat

Tutorial on building an angular application.
JavaScript
3,128
star
14

batarang

AngularJS WebInspector Extension for Chrome
JavaScript
2,444
star
15

material-start

Starter Repository for AngularJS Material
JavaScript
2,214
star
16

universal-starter

Angular Universal starter kit by @AngularClass
TypeScript
2,028
star
17

mobile-toolkit

Tools for building progressive web apps with Angular
JavaScript
1,344
star
18

in-memory-web-api

The code for this project has moved to the angular/angular repo. This repo is now archived.
TypeScript
1,172
star
19

angular.io

Website for the Angular project (see github.com/angular/angular for the project repo)
HTML
1,032
star
20

angular2-seed

TypeScript
1,011
star
21

material.angular.io

Docs site for Angular Components
TypeScript
859
star
22

di.js

Dependency Injection Framework for the future generations...
JavaScript
822
star
23

react-native-renderer

Use Angular and React Native to build applications for Android and iOS
TypeScript
789
star
24

dgeni

Flexible JavaScript documentation generator used by AngularJS, Protractor and other JS projects
TypeScript
770
star
25

angular-cn

Chinese localization of angular.io
Pug
761
star
26

vscode-ng-language-service

Angular extension for Visual Studio Code
TypeScript
757
star
27

router

The Angular 1 Component Router
JavaScript
667
star
28

angular-electron

Angular2 + Electron
TypeScript
610
star
29

devkit

549
star
30

bower-material

This repository is used for publishing the AngularJS Material v1.x library
JavaScript
506
star
31

watchtower.js

ES6 Port of Angular.dart change detection code.
JavaScript
410
star
32

preboot

Coordinate transfer of state from server to client view for isomorphic/universal JavaScript web applications
TypeScript
384
star
33

angular-hint

run-time hinting for AngularJS applications
JavaScript
368
star
34

angular-bazel-example

MOVED to the bazel nodejs monorepo πŸ‘‰
TypeScript
350
star
35

builtwith.angularjs.org

builtwith.angularjs.org
HTML
271
star
36

protractor-accessibility-plugin

Runs a set of accessibility audits
JavaScript
263
star
37

angularjs.org

code for angularjs.org site
JavaScript
260
star
38

angular-update-guide

An interactive guide to updating the version of Angular in your apps
TypeScript
245
star
39

webdriver-manager

A binary manager for E2E testing
TypeScript
227
star
40

bower-angular

Bower package for AngularJS
CSS
224
star
41

angular-ja

repository for Japanese localization of angular.io
HTML
208
star
42

ngSocket

WebSocket support for angular
JavaScript
204
star
43

peepcode-tunes

Peepcode's Backbone.js Music Player Reimplemented in AngularJS
JavaScript
204
star
44

clutz

Closure to TypeScript `.d.ts` generator
Java
163
star
45

benchpress

JavaScript
160
star
46

code.angularjs.org

code.angularjs.org
153
star
47

ngcc-validation

Angular Ivy library compatibility validation project
TypeScript
146
star
48

dgeni-packages

A collection of dgeni packages for generating documentation from source code.
JavaScript
143
star
49

bower-angular-route

angular-route bower repo
JavaScript
143
star
50

atscript-playground

A repo to play with AtScript.
JavaScript
141
star
51

bower-angular-animate

Bower package for the AngularJS animation module
JavaScript
137
star
52

protractor-cookbook

Examples for using Protractor in various common scenarios.
TypeScript
130
star
53

diary.js

Flexible logging and profiling library for JavaScript
JavaScript
127
star
54

bower-angular-i18n

internationalization module for AngularJS
JavaScript
125
star
55

ts-minify

A tool to aid minification of Typescript code, using Typescript's type information.
TypeScript
119
star
56

closure-demo

TypeScript
114
star
57

ngMigration-Forum

109
star
58

material-adaptive

Adaptive template development with Angular Material
JavaScript
101
star
59

watScript

The next generation JavaScript language that will kill ALL the frameworks!
101
star
60

bower-angular-sanitize

angular-sanitize bower repo
JavaScript
99
star
61

code-of-conduct

A code of conduct for all Angular projects
99
star
62

clang-format

Node repackaging of the clang-format native binary
Python
97
star
63

tactical

Data access library for Angular
TypeScript
93
star
64

bower-angular-resource

angular-resource bower repo
JavaScript
92
star
65

dashboard.angularjs.org

AngularJS Dashboard
JavaScript
89
star
66

angular-jquery-ui

jQueryUI widgets wrapped as angular widgets
JavaScript
88
star
67

bower-angular-mocks

angular-mocks.js bower repo
JavaScript
87
star
68

bower-angular-cookies

angular-cookies bower repo
JavaScript
85
star
69

issue-zero

TypeScript
82
star
70

bower-angular-touch

JavaScript
79
star
71

templating

Templating engine for Angular 2.0
JavaScript
76
star
72

a

Library for annotating ES5
JavaScript
67
star
73

material-icons

Common resources for material design in AngularJS
66
star
74

vladivostok

TypeScript
65
star
75

bower-angular-messages

JavaScript
63
star
76

angular-component-spec

Specification for reusable AngularJS components
61
star
77

ci.angularjs.org

ci.angularjs.org CI server scripts
Shell
60
star
78

projects

github reference application for Angular 2.0
JavaScript
58
star
79

dev-infra

Angular Development Infrastructure
JavaScript
57
star
80

code.material.angularjs.org

Documentation site for AngularJS Material
HTML
50
star
81

material-tools

Tools for AngularJS Material
TypeScript
47
star
82

jasminewd

Adapter for Jasmine-to-WebDriverJS
JavaScript
46
star
83

material-update-tool

Standalone update tool for updating Angular CDK and Material
TypeScript
46
star
84

material-builds

Build snapshots for @angular/material
JavaScript
45
star
85

material2-docs-content

Docs content for @angular/material
HTML
37
star
86

benchpress-tree

A reference implementation of a benchpress deep-tree benchmark as seen in Angular
JavaScript
37
star
87

cdk-builds

Angular CDK builds
JavaScript
37
star
88

router-builds

@angular/router build artifacts
JavaScript
36
star
89

angular-ko

HTML
36
star
90

prophecy

Deferred/Promise for AngularJS 2.0
JavaScript
36
star
91

answers-app

TypeScript
36
star
92

assert

A runtime type assertion library.
JavaScript
35
star
93

ngo

TypeScript
34
star
94

protractor-console-plugin

Checks the browser log after each test for warnings and errors
JavaScript
34
star
95

codelabs

31
star
96

introduction-to-angular

TypeScript
31
star
97

microsites

Master repository for sites on the angular.io subdomains (universal.angular.io, material.angular.io, etc)
HTML
29
star
98

core-builds

@angular/core build artifacts
JavaScript
29
star
99

ngtools-webpack-builds

Build artifacts for @ngtools/webpack
JavaScript
28
star
100

service-worker-builds

Build artifacts for @angular/service-worker
JavaScript
27
star