swc/tests/serde/colors.ts
강동윤 51558c6c36
Final groundwork for plugin (#474)
swc:
 - add serialization tests

ast_node:
 - handle `*` tag properly

swc_ecma_ast:
 - update serialization of ExprOrSpread
2019-11-30 11:12:34 +09:00

90 lines
1.5 KiB
TypeScript

'use strict';
class Foo {
foo(): void {}
}
class Bar extends Foo {
foo(): void {
super.foo();
}
async bar() {}
}
class Baz extends Bar {
foo(): void {
super.foo();
this.baz()
}
baz(): void {
}
async other() : Promise<void> {
this.baz()
await super.bar()
}
}
/**
* Extract red color out of a color integer:
*
* 0x00DEAD -> 0x00
*
* @param {Number} color
* @return {Number}
*/
function red( color: number )
{
let foo: number = 3.14;
return color >> 16;
}
/**
* Extract green out of a color integer:
*
* 0x00DEAD -> 0xDE
*
* @param {Number} color
* @return {Number}
*/
function green( color: number )
{
return ( color >> 8 ) & 0xFF;
}
/**
* Extract blue color out of a color integer:
*
* 0x00DEAD -> 0xAD
*
* @param {Number} color
* @return {Number}
*/
function blue( color: number )
{
return color & 0xFF;
}
/**
* Converts an integer containing a color such as 0x00DEAD to a hex
* string, such as '#00DEAD';
*
* @param {Number} int
* @return {String}
*/
function intToHex( int: number )
{
const mask = '#000000';
const hex = int.toString( 16 );
return mask.substring( 0, 7 - hex.length ) + hex;
}
/**
* Converts a hex string containing a color such as '#00DEAD' to
* an integer, such as 0x00DEAD;
*
* @param {Number} num
* @return {String}
*/
function hexToInt( hex: string )
{
return parseInt( hex.substring( 1 ), 16 );
}
module.exports = {
red,
green,
blue,
intToHex,
hexToInt,
};