Skip to content

Commit ef1557b

Browse files
committed
temp
2 parents ea4e0e4 + 3163abb commit ef1557b

File tree

89 files changed

+13238
-109683
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+13238
-109683
lines changed

.eslintrc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ module.exports = {
6969
// Quite common in scenarios where an iteration starts at `current = this`.
7070
"@typescript-eslint/no-this-alias": "off",
7171

72-
// Disabled here, but enabled again for JavaScript files
72+
// Disabled here, but enabled again for JavaScript files.
7373
"no-unused-vars": "off",
7474

75-
// Disabled here, but enabled again for TypeScript files
75+
// Disabled here, but enabled again for TypeScript files.
7676
"@typescript-eslint/no-unused-vars": "off"
7777
},
7878
overrides: [

.github/workflows/publish.yml

Lines changed: 7 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,17 @@ on:
44
branches:
55
- master
66
jobs:
7-
publish:
8-
name: "Packages"
7+
release:
8+
name: Packages
99
if: github.repository == 'DuncanUszkay1/assemblyscript'
1010
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@v1
1313
with:
14-
ref: release
14+
ref: master
1515
- uses: dcodeIO/setup-node-nvm@master
1616
with:
1717
node-version: current
18-
- name: Merge master
19-
env:
20-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21-
run: |
22-
git config user.name "GitHub Actions"
23-
git config user.email "actions@github.com"
24-
git remote set-url origin "https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
25-
git fetch origin
26-
git merge origin/master
2718
- name: Install dependencies
2819
run: npm ci
2920
- name: Build distribution files
@@ -32,41 +23,8 @@ jobs:
3223
npm run build
3324
- name: Test distribution files
3425
run: npm test
35-
- name: Set up version
36-
run: |
37-
VERSION=$(node -e "console.log(require('./package.json').version)")
38-
git add --force dist/*
39-
if git rev-parse v$VERSION >/dev/null 2>&1; then
40-
VERSION=$VERSION-nightly.$(date "+%Y%m%d")
41-
if git rev-parse v$VERSION >/dev/null 2>&1; then
42-
echo "Nightly $VERSION does already exist."
43-
exit 1
44-
fi
45-
echo ::set-env name=CHANNEL::nightly
46-
echo "Committing nightly ($VERSION) ..."
47-
git commit -m "Nightly v$VERSION"
48-
npm version $VERSION --no-git-tag-version --force
49-
else
50-
echo ::set-env name=CHANNEL::latest
51-
echo "Committing release ($VERSION) ..."
52-
git commit --allow-empty -m "Release v$VERSION"
53-
fi
54-
echo ::set-env name=VERSION::$VERSION
55-
cd lib/loader
56-
npm version $VERSION --no-git-tag-version --force
57-
cd ../..
58-
- name: Create tag and push distribution files
59-
run: |
60-
git tag v$VERSION
61-
git push origin release
62-
git push origin v$VERSION
63-
- name: Publish to npm
26+
- name: Make semantic release
6427
env:
65-
NPM_REGISTRY: "registry.npmjs.org"
66-
NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
67-
run: |
68-
npm config set "//${NPM_REGISTRY}/:_authToken=${NPM_AUTH_TOKEN}"
69-
npm publish --tag $CHANNEL
70-
cd lib/loader
71-
npm publish --tag $CHANNEL --access public
72-
cd ../..
28+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
30+
run: node node_modules/semantic-release/bin/semantic-release.js --unstable

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22
<a href="https://assemblyscript.org" target="_blank" rel="noopener"><img width="100" src="https://avatars1.githubusercontent.com/u/28916798?s=200&v=4" alt="AssemblyScript logo"></a>
33
</p>
44

5-
<h1 align="center">AssemblyScript Compiler</h1>
6-
75
<p align="center">
8-
<a href="https://github.com/AssemblyScript/assemblyscript/actions"><img src="https://github.com/AssemblyScript/assemblyscript/workflows/Test/badge.svg?branch=master&event=push" alt="Actions Status" /></a>
9-
<a href="https://www.npmjs.com/package/assemblyscript"><img src="https://img.shields.io/npm/v/assemblyscript.svg?color=0074C1" alt="npm package" /></a>
10-
<a href="https://www.npmjs.com/package/assemblyscript"><img src="https://img.shields.io/npm/v/assemblyscript/nightly.svg?color=0074C1" alt="npm package (nightly)" /></a>
6+
<a href="https://github.com/AssemblyScript/assemblyscript/actions"><img src="https://github.com/AssemblyScript/assemblyscript/workflows/Test/badge.svg?branch=master&event=push" alt="Test status" /></a>
7+
<a href="https://github.com/AssemblyScript/assemblyscript/actions"><img src="https://github.com/AssemblyScript/assemblyscript/workflows/Publish/badge.svg?branch=master&event=schedule" alt="Publish status" /></a>
8+
<a href="https://www.npmjs.com/package/assemblyscript"><img src="https://img.shields.io/npm/v/assemblyscript.svg?&label=&logo=npm&logoColor=ffffff&labelColor=eeeeee&color=cb3837" alt="npm package" /></a>
9+
<a href="https://discord.gg/U63XU2J"><img src="https://img.shields.io/discord/721472913886281818.svg?label=&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2" alt="Discord online" /></a>
1110
</p>
1211

13-
<p align="justify">AssemblyScript compiles a strict variant of <a href="http://www.typescriptlang.org">TypeScript</a> (basically JavaScript with types) to <a href="http://webassembly.org">WebAssembly</a> using <a href="https://github.com/WebAssembly/binaryen">Binaryen</a>. It generates lean and mean WebAssembly modules while being just an <code>npm install</code> away.</p>
12+
<p align="justify"><strong>AssemblyScript</strong> compiles a strict variant of <a href="http://www.typescriptlang.org">TypeScript</a> (basically JavaScript with types) to <a href="http://webassembly.org">WebAssembly</a> using <a href="https://github.com/WebAssembly/binaryen">Binaryen</a>. It generates lean and mean WebAssembly modules while being just an <code>npm install</code> away.</p>
1413

15-
<p align="center">
16-
<a href="https://assemblyscript.org">About</a> ·
17-
<a href="https://assemblyscript.org/introduction.html">Introduction</a> ·
18-
<a href="https://assemblyscript.org/quick-start.html">Quick start</a> ·
19-
<a href="https://assemblyscript.org/development.html">Development instructions</a>
20-
</p>
14+
<h3 align="center">
15+
<a href="https://assemblyscript.org">About</a> &nbsp;·&nbsp;
16+
<a href="https://assemblyscript.org/introduction.html">Introduction</a> &nbsp;·&nbsp;
17+
<a href="https://assemblyscript.org/quick-start.html">Quick&nbsp;start</a> &nbsp;·&nbsp;
18+
<a href="https://assemblyscript.org/development.html">Development&nbsp;instructions</a>
19+
</h3>
20+
<br>
2121

2222
<h2 align="center">Contributors</h2>
2323

cli/asc.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@
188188
" tail-calls Tail call operations.",
189189
" multi-value Multi value types."
190190
],
191-
"type": "S"
191+
"type": "S",
192+
"mutuallyExclusive": "disable"
192193
},
193194
"disable": {
194195
"category": "Features",
@@ -198,7 +199,8 @@
198199
" mutable-globals Mutable global imports and exports.",
199200
""
200201
],
201-
"type": "S"
202+
"type": "S",
203+
"mutuallyExclusive": "enable"
202204
},
203205
"use": {
204206
"category": "Features",

cli/util/options.d.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,19 @@
33
* @license Apache-2.0
44
*/
55

6+
/** A set of options. */
7+
export interface OptionSet {
8+
[key: string]: number | string
9+
}
10+
611
/** Command line option description. */
712
export interface OptionDescription {
813
/** Textual description. */
914
description?: string | string[],
1015
/** Data type. One of (b)oolean [default], (i)nteger, (f)loat or (s)tring. Uppercase means multiple values. */
1116
type?: "b" | "i" | "f" | "s" | "I" | "F" | "S",
1217
/** Substituted options, if any. */
13-
value?: { [key: string]: number | string },
18+
value?: OptionSet,
1419
/** Short alias, if any. */
1520
alias?: string
1621
/** The default value, if any. */
@@ -27,19 +32,17 @@ interface Config {
2732
/** Parsing result. */
2833
interface Result {
2934
/** Parsed options. */
30-
options: { [key: string]: number | string },
35+
options: OptionSet,
3136
/** Unknown options. */
3237
unknown: string[],
3338
/** Normal arguments. */
3439
arguments: string[],
3540
/** Trailing arguments. */
36-
trailing: string[],
37-
/** Provided arguments from the cli. */
38-
provided: Set<string>
41+
trailing: string[]
3942
}
4043

4144
/** Parses the specified command line arguments according to the given configuration. */
42-
export function parse(argv: string[], config: Config): Result;
45+
export function parse(argv: string[], config: Config, propagateDefaults?: boolean): Result;
4346

4447
/** Help formatting options. */
4548
interface HelpOptions {
@@ -53,3 +56,9 @@ interface HelpOptions {
5356

5457
/** Generates the help text for the specified configuration. */
5558
export function help(config: Config, options?: HelpOptions): string;
59+
60+
/** Merges two sets of options into one, preferring the current over the parent set. */
61+
export function merge(config: Config, currentOptions: OptionSet, parentOptions: OptionSet): OptionSet;
62+
63+
/** Populates default values on a parsed options result. */
64+
export function addDefaults(config: Config, options: OptionSet): OptionSet;

cli/util/options.js

Lines changed: 103 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@ const colorsUtil = require("./colors");
1616
// S | string array
1717

1818
/** Parses the specified command line arguments according to the given configuration. */
19-
function parse(argv, config) {
19+
function parse(argv, config, propagateDefaults = true) {
2020
var options = {};
2121
var unknown = [];
2222
var args = [];
2323
var trailing = [];
24-
var provided = new Set();
2524

2625
// make an alias map and initialize defaults
2726
var aliases = {};
@@ -54,13 +53,15 @@ function parse(argv, config) {
5453
else { args.push(arg); continue; } // argument
5554
}
5655
if (option) {
57-
if (option.type == null || option.type === "b") {
58-
options[key] = true; // flag
59-
provided.add(key);
56+
if (option.value) {
57+
// alias setting fixed values
58+
Object.keys(option.value).forEach(k => options[k] = option.value[k]);
59+
} else if (option.type == null || option.type === "b") {
60+
// boolean flag not taking a value
61+
options[key] = true;
6062
} else {
61-
// the argument was provided
62-
if (i + 1 < argv.length && argv[i + 1].charCodeAt(0) != 45) { // present
63-
provided.add(key);
63+
if (i + 1 < argv.length && argv[i + 1].charCodeAt(0) != 45) {
64+
// non-boolean with given value
6465
switch (option.type) {
6566
case "i": options[key] = parseInt(argv[++i], 10); break;
6667
case "I": options[key] = (options[key] || []).concat(parseInt(argv[++i], 10)); break;
@@ -70,7 +71,8 @@ function parse(argv, config) {
7071
case "S": options[key] = (options[key] || []).concat(argv[++i].split(",")); break;
7172
default: unknown.push(arg); --i;
7273
}
73-
} else { // omitted
74+
} else {
75+
// non-boolean with omitted value
7476
switch (option.type) {
7577
case "i":
7678
case "f": options[key] = option.default || 0; break;
@@ -82,12 +84,12 @@ function parse(argv, config) {
8284
}
8385
}
8486
}
85-
if (option.value) Object.keys(option.value).forEach(k => options[k] = option.value[k]);
8687
} else unknown.push(arg);
8788
}
8889
while (i < k) trailing.push(argv[i++]); // trailing
90+
if (propagateDefaults) addDefaults(config, options);
8991

90-
return { options, unknown, arguments: args, trailing, provided };
92+
return { options, unknown, arguments: args, trailing };
9193
}
9294

9395
exports.parse = parse;
@@ -138,3 +140,93 @@ function help(config, options) {
138140
}
139141

140142
exports.help = help;
143+
144+
/** Sanitizes an option value to be a valid value of the option's type. */
145+
function sanitizeValue(value, type) {
146+
if (value != null) {
147+
switch (type) {
148+
case undefined:
149+
case "b": return Boolean(value);
150+
case "i": return Math.trunc(value) || 0;
151+
case "f": return Number(value) || 0;
152+
case "s": return String(value);
153+
case "I": {
154+
if (!Array.isArray(value)) value = [ value ];
155+
return value.map(v => Math.trunc(v) || 0);
156+
}
157+
case "F": {
158+
if (!Array.isArray(value)) value = [ value ];
159+
return value.map(v => Number(v) || 0);
160+
}
161+
case "S": {
162+
if (!Array.isArray(value)) value = [ value ];
163+
return value.map(String);
164+
}
165+
}
166+
}
167+
return undefined;
168+
}
169+
170+
/** Merges two sets of options into one, preferring the current over the parent set. */
171+
function merge(config, currentOptions, parentOptions) {
172+
const mergedOptions = {};
173+
for (const [key, { type, mutuallyExclusive }] of Object.entries(config)) {
174+
let currentValue = sanitizeValue(currentOptions[key], type);
175+
let parentValue = sanitizeValue(parentOptions[key], type);
176+
if (currentValue == null) {
177+
if (parentValue != null) {
178+
// only parent value present
179+
if (Array.isArray(parentValue)) {
180+
let exclude;
181+
if (mutuallyExclusive != null && (exclude = currentOptions[mutuallyExclusive])) {
182+
mergedOptions[key] = parentValue.filter(value => !exclude.includes(value));
183+
} else {
184+
mergedOptions[key] = parentValue.slice();
185+
}
186+
} else {
187+
mergedOptions[key] = parentValue;
188+
}
189+
}
190+
} else if (parentValue == null) {
191+
// only current value present
192+
if (Array.isArray(currentValue)) {
193+
mergedOptions[key] = currentValue.slice();
194+
} else {
195+
mergedOptions[key] = currentValue;
196+
}
197+
} else {
198+
// both current and parent values present
199+
if (Array.isArray(currentValue)) {
200+
let exclude;
201+
if (mutuallyExclusive != null && (exclude = currentOptions[mutuallyExclusive])) {
202+
mergedOptions[key] = [
203+
...currentValue,
204+
...parentValue.filter(value => !currentValue.includes(value) && !exclude.includes(value))
205+
];
206+
} else {
207+
mergedOptions[key] = [
208+
...currentValue,
209+
...parentValue.filter(value => !currentValue.includes(value)) // dedup
210+
];
211+
}
212+
} else {
213+
mergedOptions[key] = currentValue;
214+
}
215+
}
216+
}
217+
return mergedOptions;
218+
}
219+
220+
exports.merge = merge;
221+
222+
/** Populates default values on a parsed options result. */
223+
function addDefaults(config, options) {
224+
for (const [key, { default: defaultValue }] of Object.entries(config)) {
225+
if (options[key] == null && defaultValue != null) {
226+
options[key] = defaultValue;
227+
}
228+
}
229+
return options;
230+
}
231+
232+
exports.addDefaults = addDefaults;

0 commit comments

Comments
 (0)