research

Javascript transpilers

Abstract

U ovom radu predstavljen je koncept transpilera (engl. transpilers) tj. source-to-source prevoditelja. Ono što transpileri zapravo čine je pretvaranje, tj. prevođenje jednog programskog jezika u drugi programski jezik. Ovaj rad je usredotočen na Javascript transpilere za koje kažemo da ciljaju Javascript programski jezik. Kroz rad je predstavljeno više transpilera, a u najviše detalja je opisan Babel, CoffeeScript i TypeScript. Tome je prethodio uvod u ECMAScript i njegove verzije kroz godine. Babel je transpiler za Javascript koji može prevesti najnoviju verziju Javascripta u kod koji se pokreće u svakom internetskom pregledniku. Opisana su njegova svojstva, dani primjeri koda i primjeri nove sintakse koja dolazi u ES17 te je prikazana ugrađena podrška za React JSX nadodatke te Flow anotacije. Opisan je i CoffeeScript transpiler, transpiler koji omoguće korištenje mnogih značajki Javascripta dodavanjem sintaktičkog šećera (engl. syntactic sugar) u Javascript. Prikazana i opisana je sintaksa CoffeeScripta, koja nema točke zareze i vitičaste zagrade, te ima sličnu sintaksu Pythonu i Rubyju. Iz ovih razloga je pisanje CoffeeScript koda brzo i bezbolno, te ista svojstva olakšavaju čitanje i održavanje. Opisane su i neke ključne riječi CoffeeScripta, način kako CoffeeScript radi s određenim operatorima i integracija strogog načina. Može se zaključiti da CoffeeScript kod nakon prevođenja postaje jednako uspješan ili u nekim slučajevima još učinkovitiji Javascript kod. Naposljetku je opisan i TypeScript transpiler. Navede su bitne značajke TypeScripta, a one su neobavezno statični tipovi u kodu, te koncept i realizacija klasa i sučelja. Najveća prednost TypeScripta, osim što u Javascript programski jezik uvodi objektno orijentirano programiranje, što pruža mogućnost bogatijeg razvojnog okruženja gdje je puno lakše uočiti precizne greške prilikom pisanja koda. Pisanje programa u TypeScriptu je brzo i zbog dobrog prevoditelja, broj grešaka je minimalan.This paper introduced the concept of transpilers (source-to-source translators). What transpilers actually do is converting, i.e. translating a programming language into another programming language. This paper focuses on the Javascript transpilers which target Javascript programming language. Several transpilers have been introduced through the paper with most focus on Babel, CoffeeScript and TypeScript. Before that necessary introduction to ECMAScript and it's versions throughout years was presented. Babel is a Javascript transpiler that can translate the latest version of Javascript into the code that is run on every internet browser. This paper described its features, presented code examples, examples of new syntax coming to ES17 and built-in features necessary for support React JSX additions and Flow Annotation. Papers also described CoffeeScript transpiler, a transpiler that enables the use of many Javascript features by adding syntactic sugar to Javascript. The CoffeeScripta syntax, which has no semicolons and curly braces, is depicted and described. CoffeeScript has similar syntax to Python and Ruby. For these reasons, writing of the CoffeeScript code is quick and painless, and it’s also easy to read and maintain. Some CoffeeScripta keywords are described, how CoffeeScript works with specific operators and strict mode. It can be concluded that the CoffeeScript code after translating becomes equally successful or in some cases even more effective Javascript code. Finally, TypeScript transpiler is also described. Presented are the essential features of TypeScript, which are optional static types in the code, as well as concept and realization of classes and interfaces. The biggest advantage of TypeScript, beside the introduction of objectoriented language features in Javascript is the fact it provides a richer development environment where it is much easier to perceive precise errors when writing code. Writing a program in TypeScript is fast and due to its great compiler, the number of errors remains at minimum

    Similar works