On the previous version, the default file was not being loaded correctly. Now, it is fixed
Followed by a number, this keyword allowes you to repeat an action several times
3 times {
print 'hello world!'
}Note: floating point numbers are instantly floored;
timesis not a reserved keyword
->operator can be used to execute a function multiple times, and return an array with results
let elementsToWatch = document.querySelector->(
'#item1',
'#item2',
'#item6'
)
// ... do something with the arrayTo call the function with multiple arguments, use
&prefix with()
// read files, and join them with a new line
let code = fs.readFileSync->(
&(path1, 'utf8'),
&(path2, 'utf8'),
&(path3, 'utf8')
).join('\n')
~/is used to do division values with floating part drop
5 / 2 // 2.5
5 ~/ 2 // 2while true {
x += 1
break
when x > 1_000
}EOL token had a bug, that could accidentally match strings. Now, it is fixed
JavaScript module imports are now available to use Note: you don't have to use
{}to import multiple items from the import
// import everything
import * as lib from 'lib'
// import specific items
import min, max from 'math'
// solly import
import 'addon'
// import with aliases
import sin as s, cos as c from 'math'export function doSomething() {
//...your code here
}
export mainValue // automatically converted to export { mainValue }
export const someConst = 10
export let a = 10
\nand\rnow are replaced with\x0Aand\x0Drespectively
You can use JavaScript like template literals, and use
${}to insert a BaseScript syntax
`Hello, ${clients[].name}` //get the last client's nameNow, arrow functions supported
let func = (Int a, Int b) => {a + b} // automatically returns
// Not supported
let func = (Int a, Int b) =>: a + b
let func = (Int a, Int b) => do a + bNote: inline arrow functions are not implemented yet. Use block level scopes instead, as a single statemented scope will automatically return the result, if possible
You can use this statements with a condition usigng
whenandwhen notkeywords
while i < sizeof array {
break when not array[i] == true
i++
}
let result = ''
for i in object {
continue when typeof object[i] != 'String'
result += object[i]
}
function someFunction(a, b) {
return false when not a instanceof b
return when a instanceof SomeClass
}Now you can use the
else ifblock with more ease
if a: 10
else if b: 20
else if c: 30
else: 40class Country {
constructor() {}
import() {}
export() {}
}global.a = 10
// before
print global.a
// now
print a // 10function values(...all_args) {
print all_args
}Note: rest operator will be added in upcoming releases for this syntax
let {a, b, c} = object
// same as
let a = object.a
let b = object.b
let c = object.cIf you want to get the basescript file or directory, use:
@dirnameand
@filenamelet z = {message: 'hello', type: 'string'}
let object = {}
// later on in your code
object.{
formal: true,
...z
}
print object
// output: { message: 'hello', type: 'string', formal: true }This is a quicker way to add properties or methods to your object.
Arrow operator returns an array of values, which derive from the original object/array. It can be used to call methods, retract an item, get a value of the property, or simply to store some data
let builder = {
prepare() {
return doSomePreparation()
},
isOK() {
return true
},
isDone() {
return false
}
}
// using the arrow operator
let project = builder->[
prepare(),
isOK(),
isDone()
]
// we can retract data as follows
project[1] // trueBaseScript projects builder already uses this operator
builder->[
//emptyDir(),
closurify(),
git(),
packageJSON(),
//npm(),
copyFolders(),
waitForCli()
]
@ignoreis a block level element, that can be used to exclude the content of the block body inside the final file
Note: key difference between a comment and an
@ignoreblock is that your code still needs to be valid
// uncomment if not in production
@ignore:
getDeveloperTools() // this will not appear in the final file
// neither will this
@ignore {
getDeveloperTools(@dirname)
}Now, you can use the
switch*statement as a value
let number = switch* typeof n {
case 'Number': n
default: 0
}Note:
cases automatically return value and may contain only one statement
You can use
case*to automatically break the case
switch n {
case 1:
console.log(1)
break
// same as
case* 2:
console.log(2)
}