diff --git a/.gitignore b/.gitignore index d33a9d46..2497ddd8 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,8 @@ yarn-debug.log* yarn-error.log* # Dependency directories -node_modules/ \ No newline at end of file +node_modules/ + +.DS_Store +**/.DS_Store +references/ diff --git a/CHANGELOG.md b/CHANGELOG.md index b28a4f95..b592fbf8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,47 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## 1.0.0-beta.0 (2026-05-12) + +Sync with upstream [Alloy v3.0.0](https://github.com/tidev/alloy/tree/3.0.0). Both `alloy-compiler` and `alloy-utils` jump from `0.2.7` to `1.0.0-beta.0` as the pre-release line for the v3 alignment. + +### BREAKING CHANGES + +* **node:** Minimum Node.js version is now `20.18.1` (was `10.0.0`). +* **compiler:** Generated controller code shape changed in production builds (`retainLines: false`, ES6 module trimming, collection-binding null-safety). Compiled output of every component will differ from previous versions. +* **compiler:** Babel transform now receives a `filename` argument, enabling `.babelrc` / `babel.config.js` discovery in downstream Alloy projects. Projects with one in scope will see their build behavior change. +* **runtime:** Default Backbone version constant bumped to `1.6.0` (`SUPPORTED_BACKBONE_VERSIONS` updated in `alloy-utils`). +* **runtime:** Vendored `moment` updated to 2.30.x; lang catalog expanded to 137 files (matches upstream). +* **deps:** `chmodr` dependency removed; `lodash`, `@babel/*`, `fs-extra`, `source-map`, `moment`, `resolve`, `node.extend` version ranges bumped to match upstream v3. +* **deps:** Legacy `jsonlint` and `xmldom` dependencies dropped from `alloy-utils` in favor of `@prantlf/jsonlint` and `@xmldom/xmldom`. + +### Features + +* Sync with Alloy v3.0.0 across `compile/parsers`, `compile/ast`, `compile/sourceMapper`, `compile/compilerUtils`, `compilers/component`, `builtins`, and `common/constants`. +* Add 10 missing parser pass-throughs from upstream `31328743`: `Ti.UI.ActivityIndicator`, `Column`, `MaskedImage`, `Notification`, `ProgressBar`, `RefreshControl`, `Row`, `SearchBar`, `Shortcut`, `ShortcutItem`. Includes regression tests. +* Generate source maps for widget library files (`ba8d4c22`). +* Add end-to-end smoke snapshot test (`smoke.spec.js`) covering the `test-app` fixture component compile. + +### Bug Fixes + +* Restore `isNodeForCurrentPlatform` guard in `Alloy.Abstract._ItemContainer` so platform-filtered children are skipped correctly (`4f86263c`). +* Use `path.join` in `sourceMapper.js` instead of manual string concat (`537107de`). +* Skip widget sourcemap emission when sourcemaps are disabled (`b1259b1f`). +* Fix broken `require('../../../tiapp')` import in `Ti.UI.OptionBar` parser (devkit-local pre-existing latent bug, surfaced during sync prep). +* `Alloy.Abstract.Option.js` emits `const` declarations to avoid implicit-global assignment under strict mode (devkit delta on top of `93c2df14`; supersedes upstream `ce5b4b13`). + +### Chores + +* Rebrand attribution to TiDev, Inc. (`LICENSE` copyright, `package.json` author fields, repo URLs). +* Delete stray `Ti.UI.OptionBar copy.js` parser file (accidental copy in tree). +* Delete `Ti.UI.iPhone.NavigationGroup.js` parser (removed upstream prior to v3). +* Document devkit-local divergences from upstream in `docs/DEVKIT_DELTAS.md`. +* Ignore `.DS_Store` files and local `references/` directory. + +### Out-of-scope upstream commits + +For traceability, the following upstream commits since 1.15.2 were intentionally NOT ported because they touch files outside devkit's mirrored surface (CLI commands, app templates, runtime BaseController shipped with Titanium SDK, etc.): `e45d9300`, `f5cbdd5e`, `30d9f88c`, `9f273a67`, `fb845f73`, `36b2fc87`, `29a8a54c`, `86791bc5`. See commit messages on the sync branch for per-SHA justification. + ## [0.2.7](https://github.com/appcelerator/alloy-devkit/compare/v0.2.6...v0.2.7) (2021-06-02) diff --git a/LICENSE b/LICENSE index 53e4acfa..718c879c 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright 2019-present Axway Appcelerator + Copyright 2019-2026 TiDev, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/docs/DEVKIT_DELTAS.md b/docs/DEVKIT_DELTAS.md new file mode 100644 index 00000000..d910b93f --- /dev/null +++ b/docs/DEVKIT_DELTAS.md @@ -0,0 +1,28 @@ +# Devkit Deltas + +Intentional deviations from upstream Alloy that future syncs must preserve. + +## 1. Path/import convention + +All parsers and lib files under `packages/alloy-compiler/lib/` import shared utilities from the `alloy-utils` package rather than via relative paths. This is a structural rule, not a per-file delta — apply mechanically when porting: + +- `require('../../../utils')` → `require('alloy-utils').utils` +- `require('../../../logger')` → `require('alloy-utils').logger` +- `require('../../../tiapp')` → `require('alloy-utils').tiapp` +- `require('../../../common/constants')` → `require('alloy-utils').constants` + +## 2. Package split + +Upstream Alloy ships as a single CLI; devkit splits the compile logic into two libraries: `alloy-compiler` (parsers, AST, compilers, builtins, templates) and `alloy-utils` (utils, logger, tiapp, constants, platforms, grammar). Out-of-scope upstream code: `Alloy/commands/{new,copy,move,debugger,extract-i18n,generate,info,install,purgetss,remove,test}`, `Alloy/plugin/`, top-level CLI bootstrap (`Alloy/alloy.js`). + +## 3. `Alloy.Abstract.Option.js` `const` patch + +Local fix on top of upstream `93c2df14` (`feat: support using OptionBar`). The upstream emit produces `${attrVarName} = ...` which assigns to an implicit global under strict mode. Devkit emits `const ${attrVarName} = ...` instead. Inline comment in the file points back to this entry. + +## 4. `Ti.UI.iPhone.NavigationGroup.js` removed + +Removed from devkit during the v3 sync. Upstream removed it earlier; a future sync should not re-add it as "missing file." + +## 5. Template variants + +`packages/alloy-compiler/template/{component,model}.es6.js` are devkit-only ES6-export-style templates with no upstream counterpart. They sit alongside the upstream-mirrored `component.js` / `model.js`. Out of upstream sync scope. diff --git a/lerna.json b/lerna.json index 1caf49ad..78da9cd4 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { - "version": "0.2.7", + "version": "1.0.0-beta.0", "npmClient": "yarn", "packages": [ "packages/*" diff --git a/package.json b/package.json index 49c9a262..0d201d0c 100644 --- a/package.json +++ b/package.json @@ -16,5 +16,8 @@ "jest": "^27.0.3", "lerna": "^4.0.0", "prettier": "^2.0.2" + }, + "engines": { + "node": ">=20.18.1" } } diff --git a/packages/alloy-compiler/builtins/moment.js b/packages/alloy-compiler/builtins/moment.js index 7998adb4..480b9fb3 100755 --- a/packages/alloy-compiler/builtins/moment.js +++ b/packages/alloy-compiler/builtins/moment.js @@ -1,5 +1,5 @@ //! moment.js -//! version : 2.29.4 +//! version : 2.30.1 //! authors : Tim Wood, Iskren Chernev, Moment.js contributors //! license : MIT //! momentjs.com @@ -155,24 +155,25 @@ } function isValid(m) { - if (m._isValid == null) { - var flags = getParsingFlags(m), - parsedParts = some.call(flags.parsedDateParts, function (i) { - return i != null; - }), - isNowValid = - !isNaN(m._d.getTime()) && - flags.overflow < 0 && - !flags.empty && - !flags.invalidEra && - !flags.invalidMonth && - !flags.invalidWeekday && - !flags.weekdayMismatch && - !flags.nullInput && - !flags.invalidFormat && - !flags.userInvalidated && - (!flags.meridiem || (flags.meridiem && parsedParts)); - + var flags = null, + parsedParts = false, + isNowValid = m._d && !isNaN(m._d.getTime()); + if (isNowValid) { + flags = getParsingFlags(m); + parsedParts = some.call(flags.parsedDateParts, function (i) { + return i != null; + }); + isNowValid = + flags.overflow < 0 && + !flags.empty && + !flags.invalidEra && + !flags.invalidMonth && + !flags.invalidWeekday && + !flags.weekdayMismatch && + !flags.nullInput && + !flags.invalidFormat && + !flags.userInvalidated && + (!flags.meridiem || (flags.meridiem && parsedParts)); if (m._strict) { isNowValid = isNowValid && @@ -180,12 +181,11 @@ flags.unusedTokens.length === 0 && flags.bigHour === undefined; } - - if (Object.isFrozen == null || !Object.isFrozen(m)) { - m._isValid = isNowValid; - } else { - return isNowValid; - } + } + if (Object.isFrozen == null || !Object.isFrozen(m)) { + m._isValid = isNowValid; + } else { + return isNowValid; } return m._isValid; } @@ -630,12 +630,56 @@ return isFunction(format) ? format(output) : format.replace(/%s/i, output); } - var aliases = {}; - - function addUnitAlias(unit, shorthand) { - var lowerCase = unit.toLowerCase(); - aliases[lowerCase] = aliases[lowerCase + 's'] = aliases[shorthand] = unit; - } + var aliases = { + D: 'date', + dates: 'date', + date: 'date', + d: 'day', + days: 'day', + day: 'day', + e: 'weekday', + weekdays: 'weekday', + weekday: 'weekday', + E: 'isoWeekday', + isoweekdays: 'isoWeekday', + isoweekday: 'isoWeekday', + DDD: 'dayOfYear', + dayofyears: 'dayOfYear', + dayofyear: 'dayOfYear', + h: 'hour', + hours: 'hour', + hour: 'hour', + ms: 'millisecond', + milliseconds: 'millisecond', + millisecond: 'millisecond', + m: 'minute', + minutes: 'minute', + minute: 'minute', + M: 'month', + months: 'month', + month: 'month', + Q: 'quarter', + quarters: 'quarter', + quarter: 'quarter', + s: 'second', + seconds: 'second', + second: 'second', + gg: 'weekYear', + weekyears: 'weekYear', + weekyear: 'weekYear', + GG: 'isoWeekYear', + isoweekyears: 'isoWeekYear', + isoweekyear: 'isoWeekYear', + w: 'week', + weeks: 'week', + week: 'week', + W: 'isoWeek', + isoweeks: 'isoWeek', + isoweek: 'isoWeek', + y: 'year', + years: 'year', + year: 'year', + }; function normalizeUnits(units) { return typeof units === 'string' @@ -660,11 +704,24 @@ return normalizedInput; } - var priorities = {}; - - function addUnitPriority(unit, priority) { - priorities[unit] = priority; - } + var priorities = { + date: 9, + day: 11, + weekday: 11, + isoWeekday: 11, + dayOfYear: 4, + hour: 13, + millisecond: 16, + minute: 14, + month: 8, + quarter: 7, + second: 15, + weekYear: 1, + isoWeekYear: 1, + week: 5, + isoWeek: 5, + year: 1, + }; function getPrioritizedUnits(unitsObj) { var units = [], @@ -680,96 +737,6 @@ return units; } - function isLeapYear(year) { - return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0; - } - - function absFloor(number) { - if (number < 0) { - // -0 -> 0 - return Math.ceil(number) || 0; - } else { - return Math.floor(number); - } - } - - function toInt(argumentForCoercion) { - var coercedNumber = +argumentForCoercion, - value = 0; - - if (coercedNumber !== 0 && isFinite(coercedNumber)) { - value = absFloor(coercedNumber); - } - - return value; - } - - function makeGetSet(unit, keepTime) { - return function (value) { - if (value != null) { - set$1(this, unit, value); - hooks.updateOffset(this, keepTime); - return this; - } else { - return get(this, unit); - } - }; - } - - function get(mom, unit) { - return mom.isValid() - ? mom._d['get' + (mom._isUTC ? 'UTC' : '') + unit]() - : NaN; - } - - function set$1(mom, unit, value) { - if (mom.isValid() && !isNaN(value)) { - if ( - unit === 'FullYear' && - isLeapYear(mom.year()) && - mom.month() === 1 && - mom.date() === 29 - ) { - value = toInt(value); - mom._d['set' + (mom._isUTC ? 'UTC' : '') + unit]( - value, - mom.month(), - daysInMonth(value, mom.month()) - ); - } else { - mom._d['set' + (mom._isUTC ? 'UTC' : '') + unit](value); - } - } - } - - // MOMENTS - - function stringGet(units) { - units = normalizeUnits(units); - if (isFunction(this[units])) { - return this[units](); - } - return this; - } - - function stringSet(units, value) { - if (typeof units === 'object') { - units = normalizeObjectUnits(units); - var prioritized = getPrioritizedUnits(units), - i, - prioritizedLen = prioritized.length; - for (i = 0; i < prioritizedLen; i++) { - this[prioritized[i].unit](units[prioritized[i].unit]); - } - } else { - units = normalizeUnits(units); - if (isFunction(this[units])) { - return this[units](value); - } - } - return this; - } - var match1 = /\d/, // 0 - 9 match2 = /\d\d/, // 00 - 99 match3 = /\d{3}/, // 000 - 999 @@ -790,6 +757,8 @@ // includes scottish gaelic two word and hyphenated months matchWord = /[0-9]{0,256}['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFF07\uFF10-\uFFEF]{1,256}|[\u0600-\u06FF\/]{1,256}(\s*?[\u0600-\u06FF]{1,256}){1,2}/i, + match1to2NoLeadingZero = /^[1-9]\d?/, // 1-99 + match1to2HasZero = /^([1-9]\d|\d)/, // 0-99 regexes; regexes = {}; @@ -828,6 +797,26 @@ return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); } + function absFloor(number) { + if (number < 0) { + // -0 -> 0 + return Math.ceil(number) || 0; + } else { + return Math.floor(number); + } + } + + function toInt(argumentForCoercion) { + var coercedNumber = +argumentForCoercion, + value = 0; + + if (coercedNumber !== 0 && isFinite(coercedNumber)) { + value = absFloor(coercedNumber); + } + + return value; + } + var tokens = {}; function addParseToken(token, callback) { @@ -861,6 +850,10 @@ } } + function isLeapYear(year) { + return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0; + } + var YEAR = 0, MONTH = 1, DATE = 2, @@ -871,6 +864,173 @@ WEEK = 7, WEEKDAY = 8; + // FORMATTING + + addFormatToken('Y', 0, 0, function () { + var y = this.year(); + return y <= 9999 ? zeroFill(y, 4) : '+' + y; + }); + + addFormatToken(0, ['YY', 2], 0, function () { + return this.year() % 100; + }); + + addFormatToken(0, ['YYYY', 4], 0, 'year'); + addFormatToken(0, ['YYYYY', 5], 0, 'year'); + addFormatToken(0, ['YYYYYY', 6, true], 0, 'year'); + + // PARSING + + addRegexToken('Y', matchSigned); + addRegexToken('YY', match1to2, match2); + addRegexToken('YYYY', match1to4, match4); + addRegexToken('YYYYY', match1to6, match6); + addRegexToken('YYYYYY', match1to6, match6); + + addParseToken(['YYYYY', 'YYYYYY'], YEAR); + addParseToken('YYYY', function (input, array) { + array[YEAR] = + input.length === 2 ? hooks.parseTwoDigitYear(input) : toInt(input); + }); + addParseToken('YY', function (input, array) { + array[YEAR] = hooks.parseTwoDigitYear(input); + }); + addParseToken('Y', function (input, array) { + array[YEAR] = parseInt(input, 10); + }); + + // HELPERS + + function daysInYear(year) { + return isLeapYear(year) ? 366 : 365; + } + + // HOOKS + + hooks.parseTwoDigitYear = function (input) { + return toInt(input) + (toInt(input) > 68 ? 1900 : 2000); + }; + + // MOMENTS + + var getSetYear = makeGetSet('FullYear', true); + + function getIsLeapYear() { + return isLeapYear(this.year()); + } + + function makeGetSet(unit, keepTime) { + return function (value) { + if (value != null) { + set$1(this, unit, value); + hooks.updateOffset(this, keepTime); + return this; + } else { + return get(this, unit); + } + }; + } + + function get(mom, unit) { + if (!mom.isValid()) { + return NaN; + } + + var d = mom._d, + isUTC = mom._isUTC; + + switch (unit) { + case 'Milliseconds': + return isUTC ? d.getUTCMilliseconds() : d.getMilliseconds(); + case 'Seconds': + return isUTC ? d.getUTCSeconds() : d.getSeconds(); + case 'Minutes': + return isUTC ? d.getUTCMinutes() : d.getMinutes(); + case 'Hours': + return isUTC ? d.getUTCHours() : d.getHours(); + case 'Date': + return isUTC ? d.getUTCDate() : d.getDate(); + case 'Day': + return isUTC ? d.getUTCDay() : d.getDay(); + case 'Month': + return isUTC ? d.getUTCMonth() : d.getMonth(); + case 'FullYear': + return isUTC ? d.getUTCFullYear() : d.getFullYear(); + default: + return NaN; // Just in case + } + } + + function set$1(mom, unit, value) { + var d, isUTC, year, month, date; + + if (!mom.isValid() || isNaN(value)) { + return; + } + + d = mom._d; + isUTC = mom._isUTC; + + switch (unit) { + case 'Milliseconds': + return void (isUTC + ? d.setUTCMilliseconds(value) + : d.setMilliseconds(value)); + case 'Seconds': + return void (isUTC ? d.setUTCSeconds(value) : d.setSeconds(value)); + case 'Minutes': + return void (isUTC ? d.setUTCMinutes(value) : d.setMinutes(value)); + case 'Hours': + return void (isUTC ? d.setUTCHours(value) : d.setHours(value)); + case 'Date': + return void (isUTC ? d.setUTCDate(value) : d.setDate(value)); + // case 'Day': // Not real + // return void (isUTC ? d.setUTCDay(value) : d.setDay(value)); + // case 'Month': // Not used because we need to pass two variables + // return void (isUTC ? d.setUTCMonth(value) : d.setMonth(value)); + case 'FullYear': + break; // See below ... + default: + return; // Just in case + } + + year = value; + month = mom.month(); + date = mom.date(); + date = date === 29 && month === 1 && !isLeapYear(year) ? 28 : date; + void (isUTC + ? d.setUTCFullYear(year, month, date) + : d.setFullYear(year, month, date)); + } + + // MOMENTS + + function stringGet(units) { + units = normalizeUnits(units); + if (isFunction(this[units])) { + return this[units](); + } + return this; + } + + function stringSet(units, value) { + if (typeof units === 'object') { + units = normalizeObjectUnits(units); + var prioritized = getPrioritizedUnits(units), + i, + prioritizedLen = prioritized.length; + for (i = 0; i < prioritizedLen; i++) { + this[prioritized[i].unit](units[prioritized[i].unit]); + } + } else { + units = normalizeUnits(units); + if (isFunction(this[units])) { + return this[units](value); + } + } + return this; + } + function mod(n, x) { return ((n % x) + x) % x; } @@ -919,17 +1079,9 @@ return this.localeData().months(this, format); }); - // ALIASES - - addUnitAlias('month', 'M'); - - // PRIORITY - - addUnitPriority('month', 8); - // PARSING - addRegexToken('M', match1to2); + addRegexToken('M', match1to2, match1to2NoLeadingZero); addRegexToken('MM', match1to2, match2); addRegexToken('MMM', function (isStrict, locale) { return locale.monthsShortRegex(isStrict); @@ -1095,8 +1247,6 @@ // MOMENTS function setMonth(mom, value) { - var dayOfMonth; - if (!mom.isValid()) { // No op return mom; @@ -1114,8 +1264,13 @@ } } - dayOfMonth = Math.min(mom.date(), daysInMonth(mom.year(), value)); - mom._d['set' + (mom._isUTC ? 'UTC' : '') + 'Month'](value, dayOfMonth); + var month = value, + date = mom.date(); + + date = date < 29 ? date : Math.min(date, daysInMonth(mom.year(), month)); + void (mom._isUTC + ? mom._d.setUTCMonth(month, date) + : mom._d.setMonth(month, date)); return mom; } @@ -1182,27 +1337,24 @@ longPieces = [], mixedPieces = [], i, - mom; + mom, + shortP, + longP; for (i = 0; i < 12; i++) { // make the regex if we don't have it already mom = createUTC([2000, i]); - shortPieces.push(this.monthsShort(mom, '')); - longPieces.push(this.months(mom, '')); - mixedPieces.push(this.months(mom, '')); - mixedPieces.push(this.monthsShort(mom, '')); + shortP = regexEscape(this.monthsShort(mom, '')); + longP = regexEscape(this.months(mom, '')); + shortPieces.push(shortP); + longPieces.push(longP); + mixedPieces.push(longP); + mixedPieces.push(shortP); } // Sorting makes sure if one month (or abbr) is a prefix of another it // will match the longer piece. shortPieces.sort(cmpLenRev); longPieces.sort(cmpLenRev); mixedPieces.sort(cmpLenRev); - for (i = 0; i < 12; i++) { - shortPieces[i] = regexEscape(shortPieces[i]); - longPieces[i] = regexEscape(longPieces[i]); - } - for (i = 0; i < 24; i++) { - mixedPieces[i] = regexEscape(mixedPieces[i]); - } this._monthsRegex = new RegExp('^(' + mixedPieces.join('|') + ')', 'i'); this._monthsShortRegex = this._monthsRegex; @@ -1216,69 +1368,6 @@ ); } - // FORMATTING - - addFormatToken('Y', 0, 0, function () { - var y = this.year(); - return y <= 9999 ? zeroFill(y, 4) : '+' + y; - }); - - addFormatToken(0, ['YY', 2], 0, function () { - return this.year() % 100; - }); - - addFormatToken(0, ['YYYY', 4], 0, 'year'); - addFormatToken(0, ['YYYYY', 5], 0, 'year'); - addFormatToken(0, ['YYYYYY', 6, true], 0, 'year'); - - // ALIASES - - addUnitAlias('year', 'y'); - - // PRIORITIES - - addUnitPriority('year', 1); - - // PARSING - - addRegexToken('Y', matchSigned); - addRegexToken('YY', match1to2, match2); - addRegexToken('YYYY', match1to4, match4); - addRegexToken('YYYYY', match1to6, match6); - addRegexToken('YYYYYY', match1to6, match6); - - addParseToken(['YYYYY', 'YYYYYY'], YEAR); - addParseToken('YYYY', function (input, array) { - array[YEAR] = - input.length === 2 ? hooks.parseTwoDigitYear(input) : toInt(input); - }); - addParseToken('YY', function (input, array) { - array[YEAR] = hooks.parseTwoDigitYear(input); - }); - addParseToken('Y', function (input, array) { - array[YEAR] = parseInt(input, 10); - }); - - // HELPERS - - function daysInYear(year) { - return isLeapYear(year) ? 366 : 365; - } - - // HOOKS - - hooks.parseTwoDigitYear = function (input) { - return toInt(input) + (toInt(input) > 68 ? 1900 : 2000); - }; - - // MOMENTS - - var getSetYear = makeGetSet('FullYear', true); - - function getIsLeapYear() { - return isLeapYear(this.year()); - } - function createDate(y, m, d, h, M, s, ms) { // can't just apply() to create a date: // https://stackoverflow.com/q/181348 @@ -1384,21 +1473,11 @@ addFormatToken('w', ['ww', 2], 'wo', 'week'); addFormatToken('W', ['WW', 2], 'Wo', 'isoWeek'); - // ALIASES - - addUnitAlias('week', 'w'); - addUnitAlias('isoWeek', 'W'); - - // PRIORITIES - - addUnitPriority('week', 5); - addUnitPriority('isoWeek', 5); - // PARSING - addRegexToken('w', match1to2); + addRegexToken('w', match1to2, match1to2NoLeadingZero); addRegexToken('ww', match1to2, match2); - addRegexToken('W', match1to2); + addRegexToken('W', match1to2, match1to2NoLeadingZero); addRegexToken('WW', match1to2, match2); addWeekParseToken( @@ -1460,17 +1539,6 @@ addFormatToken('e', 0, 0, 'weekday'); addFormatToken('E', 0, 0, 'isoWeekday'); - // ALIASES - - addUnitAlias('day', 'd'); - addUnitAlias('weekday', 'e'); - addUnitAlias('isoWeekday', 'E'); - - // PRIORITY - addUnitPriority('day', 11); - addUnitPriority('weekday', 11); - addUnitPriority('isoWeekday', 11); - // PARSING addRegexToken('d', match1to2); @@ -1550,24 +1618,24 @@ return m === true ? shiftWeekdays(weekdays, this._week.dow) : m - ? weekdays[m.day()] - : weekdays; + ? weekdays[m.day()] + : weekdays; } function localeWeekdaysShort(m) { return m === true ? shiftWeekdays(this._weekdaysShort, this._week.dow) : m - ? this._weekdaysShort[m.day()] - : this._weekdaysShort; + ? this._weekdaysShort[m.day()] + : this._weekdaysShort; } function localeWeekdaysMin(m) { return m === true ? shiftWeekdays(this._weekdaysMin, this._week.dow) : m - ? this._weekdaysMin[m.day()] - : this._weekdaysMin; + ? this._weekdaysMin[m.day()] + : this._weekdaysMin; } function handleStrictParse$1(weekdayName, format, strict) { @@ -1716,7 +1784,8 @@ if (!this.isValid()) { return input != null ? this : NaN; } - var day = this._isUTC ? this._d.getUTCDay() : this._d.getDay(); + + var day = get(this, 'Day'); if (input != null) { input = parseWeekday(input, this.localeData()); return this.add(input - day, 'd'); @@ -1915,13 +1984,6 @@ meridiem('a', true); meridiem('A', false); - // ALIASES - - addUnitAlias('hour', 'h'); - - // PRIORITY - addUnitPriority('hour', 13); - // PARSING function matchMeridiem(isStrict, locale) { @@ -1930,9 +1992,9 @@ addRegexToken('a', matchMeridiem); addRegexToken('A', matchMeridiem); - addRegexToken('H', match1to2); - addRegexToken('h', match1to2); - addRegexToken('k', match1to2); + addRegexToken('H', match1to2, match1to2HasZero); + addRegexToken('h', match1to2, match1to2NoLeadingZero); + addRegexToken('k', match1to2, match1to2NoLeadingZero); addRegexToken('HH', match1to2, match2); addRegexToken('hh', match1to2, match2); addRegexToken('kk', match1to2, match2); @@ -2082,7 +2144,8 @@ function isLocaleNameSane(name) { // Prevent names that look like filesystem paths, i.e contain '/' or '\' - return name.match('^[^/\\\\]*$') != null; + // Ensure name is available and function returns boolean + return !!(name && name.match('^[^/\\\\]*$')); } function loadLocale(name) { @@ -2274,21 +2337,21 @@ a[MONTH] < 0 || a[MONTH] > 11 ? MONTH : a[DATE] < 1 || a[DATE] > daysInMonth(a[YEAR], a[MONTH]) - ? DATE - : a[HOUR] < 0 || - a[HOUR] > 24 || - (a[HOUR] === 24 && - (a[MINUTE] !== 0 || - a[SECOND] !== 0 || - a[MILLISECOND] !== 0)) - ? HOUR - : a[MINUTE] < 0 || a[MINUTE] > 59 - ? MINUTE - : a[SECOND] < 0 || a[SECOND] > 59 - ? SECOND - : a[MILLISECOND] < 0 || a[MILLISECOND] > 999 - ? MILLISECOND - : -1; + ? DATE + : a[HOUR] < 0 || + a[HOUR] > 24 || + (a[HOUR] === 24 && + (a[MINUTE] !== 0 || + a[SECOND] !== 0 || + a[MILLISECOND] !== 0)) + ? HOUR + : a[MINUTE] < 0 || a[MINUTE] > 59 + ? MINUTE + : a[SECOND] < 0 || a[SECOND] > 59 + ? SECOND + : a[MILLISECOND] < 0 || a[MILLISECOND] > 999 + ? MILLISECOND + : -1; if ( getParsingFlags(m)._overflowDayOfYear && @@ -3729,16 +3792,16 @@ return diff < -6 ? 'sameElse' : diff < -1 - ? 'lastWeek' - : diff < 0 - ? 'lastDay' - : diff < 1 - ? 'sameDay' - : diff < 2 - ? 'nextDay' - : diff < 7 - ? 'nextWeek' - : 'sameElse'; + ? 'lastWeek' + : diff < 0 + ? 'lastDay' + : diff < 1 + ? 'sameDay' + : diff < 2 + ? 'nextDay' + : diff < 7 + ? 'nextWeek' + : 'sameElse'; } function calendar$1(time, formats) { @@ -4546,16 +4609,22 @@ mixedPieces = [], i, l, + erasName, + erasAbbr, + erasNarrow, eras = this.eras(); for (i = 0, l = eras.length; i < l; ++i) { - namePieces.push(regexEscape(eras[i].name)); - abbrPieces.push(regexEscape(eras[i].abbr)); - narrowPieces.push(regexEscape(eras[i].narrow)); + erasName = regexEscape(eras[i].name); + erasAbbr = regexEscape(eras[i].abbr); + erasNarrow = regexEscape(eras[i].narrow); - mixedPieces.push(regexEscape(eras[i].name)); - mixedPieces.push(regexEscape(eras[i].abbr)); - mixedPieces.push(regexEscape(eras[i].narrow)); + namePieces.push(erasName); + abbrPieces.push(erasAbbr); + narrowPieces.push(erasNarrow); + mixedPieces.push(erasName); + mixedPieces.push(erasAbbr); + mixedPieces.push(erasNarrow); } this._erasRegex = new RegExp('^(' + mixedPieces.join('|') + ')', 'i'); @@ -4588,14 +4657,6 @@ // ALIASES - addUnitAlias('weekYear', 'gg'); - addUnitAlias('isoWeekYear', 'GG'); - - // PRIORITY - - addUnitPriority('weekYear', 1); - addUnitPriority('isoWeekYear', 1); - // PARSING addRegexToken('G', matchSigned); @@ -4625,7 +4686,7 @@ this, input, this.week(), - this.weekday(), + this.weekday() + this.localeData()._week.dow, this.localeData()._week.dow, this.localeData()._week.doy ); @@ -4687,14 +4748,6 @@ addFormatToken('Q', 0, 'Qo', 'quarter'); - // ALIASES - - addUnitAlias('quarter', 'Q'); - - // PRIORITY - - addUnitPriority('quarter', 7); - // PARSING addRegexToken('Q', match1); @@ -4714,16 +4767,9 @@ addFormatToken('D', ['DD', 2], 'Do', 'date'); - // ALIASES - - addUnitAlias('date', 'D'); - - // PRIORITY - addUnitPriority('date', 9); - // PARSING - addRegexToken('D', match1to2); + addRegexToken('D', match1to2, match1to2NoLeadingZero); addRegexToken('DD', match1to2, match2); addRegexToken('Do', function (isStrict, locale) { // TODO: Remove "ordinalParse" fallback in next major release. @@ -4745,13 +4791,6 @@ addFormatToken('DDD', ['DDDD', 3], 'DDDo', 'dayOfYear'); - // ALIASES - - addUnitAlias('dayOfYear', 'DDD'); - - // PRIORITY - addUnitPriority('dayOfYear', 4); - // PARSING addRegexToken('DDD', match1to3); @@ -4776,17 +4815,9 @@ addFormatToken('m', ['mm', 2], 0, 'minute'); - // ALIASES - - addUnitAlias('minute', 'm'); - - // PRIORITY - - addUnitPriority('minute', 14); - // PARSING - addRegexToken('m', match1to2); + addRegexToken('m', match1to2, match1to2HasZero); addRegexToken('mm', match1to2, match2); addParseToken(['m', 'mm'], MINUTE); @@ -4798,17 +4829,9 @@ addFormatToken('s', ['ss', 2], 0, 'second'); - // ALIASES - - addUnitAlias('second', 's'); - - // PRIORITY - - addUnitPriority('second', 15); - // PARSING - addRegexToken('s', match1to2); + addRegexToken('s', match1to2, match1to2HasZero); addRegexToken('ss', match1to2, match2); addParseToken(['s', 'ss'], SECOND); @@ -4846,14 +4869,6 @@ return this.millisecond() * 1000000; }); - // ALIASES - - addUnitAlias('millisecond', 'ms'); - - // PRIORITY - - addUnitPriority('millisecond', 16); - // PARSING addRegexToken('S', match1to3, match1); @@ -5161,12 +5176,12 @@ toInt((number % 100) / 10) === 1 ? 'th' : b === 1 - ? 'st' - : b === 2 - ? 'nd' - : b === 3 - ? 'rd' - : 'th'; + ? 'st' + : b === 2 + ? 'nd' + : b === 3 + ? 'rd' + : 'th'; return number + output; }, }); @@ -5339,19 +5354,6 @@ } } - // TODO: Use this.as('ms')? - function valueOf$1() { - if (!this.isValid()) { - return NaN; - } - return ( - this._milliseconds + - this._days * 864e5 + - (this._months % 12) * 2592e6 + - toInt(this._months / 12) * 31536e6 - ); - } - function makeAs(alias) { return function () { return this.as(alias); @@ -5366,7 +5368,8 @@ asWeeks = makeAs('w'), asMonths = makeAs('M'), asQuarters = makeAs('Q'), - asYears = makeAs('y'); + asYears = makeAs('y'), + valueOf$1 = asMilliseconds; function clone$1() { return createDuration(this); @@ -5635,7 +5638,7 @@ //! moment.js - hooks.version = '2.29.4'; + hooks.version = '2.30.1'; setHookCallback(createLocal); @@ -5682,4 +5685,4 @@ return hooks; -}))); \ No newline at end of file +}))); diff --git a/packages/alloy-compiler/builtins/moment/lang/ar-dz.js b/packages/alloy-compiler/builtins/moment/lang/ar-dz.js index 0fe59023..720a6de9 100644 --- a/packages/alloy-compiler/builtins/moment/lang/ar-dz.js +++ b/packages/alloy-compiler/builtins/moment/lang/ar-dz.js @@ -19,14 +19,14 @@ return n === 0 ? 0 : n === 1 - ? 1 - : n === 2 - ? 2 - : n % 100 >= 3 && n % 100 <= 10 - ? 3 - : n % 100 >= 11 - ? 4 - : 5; + ? 1 + : n === 2 + ? 2 + : n % 100 >= 3 && n % 100 <= 10 + ? 3 + : n % 100 >= 11 + ? 4 + : 5; }, plurals = { s: [ diff --git a/packages/alloy-compiler/builtins/moment/lang/ar-ly.js b/packages/alloy-compiler/builtins/moment/lang/ar-ly.js index f34f140c..73aecd66 100644 --- a/packages/alloy-compiler/builtins/moment/lang/ar-ly.js +++ b/packages/alloy-compiler/builtins/moment/lang/ar-ly.js @@ -27,14 +27,14 @@ return n === 0 ? 0 : n === 1 - ? 1 - : n === 2 - ? 2 - : n % 100 >= 3 && n % 100 <= 10 - ? 3 - : n % 100 >= 11 - ? 4 - : 5; + ? 1 + : n === 2 + ? 2 + : n % 100 >= 3 && n % 100 <= 10 + ? 3 + : n % 100 >= 11 + ? 4 + : 5; }, plurals = { s: [ diff --git a/packages/alloy-compiler/builtins/moment/lang/ar-ps.js b/packages/alloy-compiler/builtins/moment/lang/ar-ps.js new file mode 100644 index 00000000..9ec31a66 --- /dev/null +++ b/packages/alloy-compiler/builtins/moment/lang/ar-ps.js @@ -0,0 +1,123 @@ +//! moment.js locale configuration +//! locale : Arabic (Palestine) [ar-ps] +//! author : Majd Al-Shihabi : https://github.com/majdal + +;(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' + && typeof require === 'function' ? factory(require('/alloy/moment')) : + typeof define === 'function' && define.amd ? define(['../moment'], factory) : + factory(global.moment) +}(this, (function (moment) { 'use strict'; + + //! moment.js locale configuration + + var symbolMap = { + 1: '١', + 2: '٢', + 3: '٣', + 4: '٤', + 5: '٥', + 6: '٦', + 7: '٧', + 8: '٨', + 9: '٩', + 0: '٠', + }, + numberMap = { + '١': '1', + '٢': '2', + '٣': '3', + '٤': '4', + '٥': '5', + '٦': '6', + '٧': '7', + '٨': '8', + '٩': '9', + '٠': '0', + }; + + var arPs = moment.defineLocale('ar-ps', { + months: 'كانون الثاني_شباط_آذار_نيسان_أيّار_حزيران_تمّوز_آب_أيلول_تشري الأوّل_تشرين الثاني_كانون الأوّل'.split( + '_' + ), + monthsShort: + 'ك٢_شباط_آذار_نيسان_أيّار_حزيران_تمّوز_آب_أيلول_ت١_ت٢_ك١'.split('_'), + weekdays: 'الأحد_الإثنين_الثلاثاء_الأربعاء_الخميس_الجمعة_السبت'.split('_'), + weekdaysShort: 'أحد_إثنين_ثلاثاء_أربعاء_خميس_جمعة_سبت'.split('_'), + weekdaysMin: 'ح_ن_ث_ر_خ_ج_س'.split('_'), + weekdaysParseExact: true, + longDateFormat: { + LT: 'HH:mm', + LTS: 'HH:mm:ss', + L: 'DD/MM/YYYY', + LL: 'D MMMM YYYY', + LLL: 'D MMMM YYYY HH:mm', + LLLL: 'dddd D MMMM YYYY HH:mm', + }, + meridiemParse: /ص|م/, + isPM: function (input) { + return 'م' === input; + }, + meridiem: function (hour, minute, isLower) { + if (hour < 12) { + return 'ص'; + } else { + return 'م'; + } + }, + calendar: { + sameDay: '[اليوم على الساعة] LT', + nextDay: '[غدا على الساعة] LT', + nextWeek: 'dddd [على الساعة] LT', + lastDay: '[أمس على الساعة] LT', + lastWeek: 'dddd [على الساعة] LT', + sameElse: 'L', + }, + relativeTime: { + future: 'في %s', + past: 'منذ %s', + s: 'ثوان', + ss: '%d ثانية', + m: 'دقيقة', + mm: '%d دقائق', + h: 'ساعة', + hh: '%d ساعات', + d: 'يوم', + dd: '%d أيام', + M: 'شهر', + MM: '%d أشهر', + y: 'سنة', + yy: '%d سنوات', + }, + preparse: function (string) { + return string + .replace(/[٣٤٥٦٧٨٩٠]/g, function (match) { + return numberMap[match]; + }) + .split('') // reversed since negative lookbehind not supported everywhere + .reverse() + .join('') + .replace(/[١٢](?![\u062a\u0643])/g, function (match) { + return numberMap[match]; + }) + .split('') + .reverse() + .join('') + .replace(/،/g, ','); + }, + postformat: function (string) { + return string + .replace(/\d/g, function (match) { + return symbolMap[match]; + }) + .replace(/,/g, '،'); + }, + week: { + dow: 0, // Sunday is the first day of the week. + doy: 6, // The week that contains Jan 6th is the first week of the year. + }, + }); + + return arPs; + +}))); diff --git a/packages/alloy-compiler/builtins/moment/lang/ar.js b/packages/alloy-compiler/builtins/moment/lang/ar.js index 902a7bed..fe960666 100644 --- a/packages/alloy-compiler/builtins/moment/lang/ar.js +++ b/packages/alloy-compiler/builtins/moment/lang/ar.js @@ -41,14 +41,14 @@ return n === 0 ? 0 : n === 1 - ? 1 - : n === 2 - ? 2 - : n % 100 >= 3 && n % 100 <= 10 - ? 3 - : n % 100 >= 11 - ? 4 - : 5; + ? 1 + : n === 2 + ? 2 + : n % 100 >= 3 && n % 100 <= 10 + ? 3 + : n % 100 >= 11 + ? 4 + : 5; }, plurals = { s: [ diff --git a/packages/alloy-compiler/builtins/moment/lang/be.js b/packages/alloy-compiler/builtins/moment/lang/be.js index 10ddfec2..c1401752 100644 --- a/packages/alloy-compiler/builtins/moment/lang/be.js +++ b/packages/alloy-compiler/builtins/moment/lang/be.js @@ -18,8 +18,8 @@ return num % 10 === 1 && num % 100 !== 11 ? forms[0] : num % 10 >= 2 && num % 10 <= 4 && (num % 100 < 10 || num % 100 >= 20) - ? forms[1] - : forms[2]; + ? forms[1] + : forms[2]; } function relativeTimeWithPlural(number, withoutSuffix, key) { var format = { diff --git a/packages/alloy-compiler/builtins/moment/lang/bs.js b/packages/alloy-compiler/builtins/moment/lang/bs.js index d17fb22d..a59d68cf 100644 --- a/packages/alloy-compiler/builtins/moment/lang/bs.js +++ b/packages/alloy-compiler/builtins/moment/lang/bs.js @@ -1,6 +1,7 @@ //! moment.js locale configuration //! locale : Bosnian [bs] //! author : Nedim Cholich : https://github.com/frontyard +//! author : Rasid Redzic : https://github.com/rasidre //! based on (hr) translation by Bojan Marković ;(function (global, factory) { @@ -12,6 +13,17 @@ //! moment.js locale configuration + function processRelativeTime(number, withoutSuffix, key, isFuture) { + switch (key) { + case 'm': + return withoutSuffix + ? 'jedna minuta' + : isFuture + ? 'jednu minutu' + : 'jedne minute'; + } + } + function translate(number, withoutSuffix, key) { var result = number + ' '; switch (key) { @@ -24,8 +36,6 @@ result += 'sekundi'; } return result; - case 'm': - return withoutSuffix ? 'jedna minuta' : 'jedne minute'; case 'mm': if (number === 1) { result += 'minuta'; @@ -36,7 +46,7 @@ } return result; case 'h': - return withoutSuffix ? 'jedan sat' : 'jednog sata'; + return withoutSuffix ? 'jedan sat' : 'jedan sat'; case 'hh': if (number === 1) { result += 'sat'; @@ -137,7 +147,7 @@ past: 'prije %s', s: 'par sekundi', ss: translate, - m: translate, + m: processRelativeTime, mm: translate, h: translate, hh: translate, diff --git a/packages/alloy-compiler/builtins/moment/lang/ca.js b/packages/alloy-compiler/builtins/moment/lang/ca.js index 9aef27a1..29953915 100644 --- a/packages/alloy-compiler/builtins/moment/lang/ca.js +++ b/packages/alloy-compiler/builtins/moment/lang/ca.js @@ -89,12 +89,12 @@ number === 1 ? 'r' : number === 2 - ? 'n' - : number === 3 - ? 'r' - : number === 4 - ? 't' - : 'è'; + ? 'n' + : number === 3 + ? 'r' + : number === 4 + ? 't' + : 'è'; if (period === 'w' || period === 'W') { output = 'a'; } diff --git a/packages/alloy-compiler/builtins/moment/lang/cs.js b/packages/alloy-compiler/builtins/moment/lang/cs.js index b6d05139..20889983 100644 --- a/packages/alloy-compiler/builtins/moment/lang/cs.js +++ b/packages/alloy-compiler/builtins/moment/lang/cs.js @@ -12,13 +12,14 @@ //! moment.js locale configuration var months = { - format: 'leden_únor_březen_duben_květen_červen_červenec_srpen_září_říjen_listopad_prosinec'.split( - '_' - ), standalone: - 'ledna_února_března_dubna_května_června_července_srpna_září_října_listopadu_prosince'.split( + 'leden_únor_březen_duben_květen_červen_červenec_srpen_září_říjen_listopad_prosinec'.split( '_' ), + format: 'ledna_února_března_dubna_května_června_července_srpna_září_října_listopadu_prosince'.split( + '_' + ), + isFormat: /DD?[o.]?(\[[^\[\]]*\]|\s)+MMMM/, }, monthsShort = 'led_úno_bře_dub_kvě_čvn_čvc_srp_zář_říj_lis_pro'.split('_'), monthsParse = [ diff --git a/packages/alloy-compiler/builtins/moment/lang/cv.js b/packages/alloy-compiler/builtins/moment/lang/cv.js index 6bd34220..a3933adc 100644 --- a/packages/alloy-compiler/builtins/moment/lang/cv.js +++ b/packages/alloy-compiler/builtins/moment/lang/cv.js @@ -43,8 +43,8 @@ var affix = /сехет$/i.exec(output) ? 'рен' : /ҫул$/i.exec(output) - ? 'тан' - : 'ран'; + ? 'тан' + : 'ран'; return output + affix; }, past: '%s каялла', diff --git a/packages/alloy-compiler/builtins/moment/lang/en-SG.js b/packages/alloy-compiler/builtins/moment/lang/en-SG.js index 338fc63d..85c99547 100644 --- a/packages/alloy-compiler/builtins/moment/lang/en-SG.js +++ b/packages/alloy-compiler/builtins/moment/lang/en-SG.js @@ -60,12 +60,12 @@ ~~((number % 100) / 10) === 1 ? 'th' : b === 1 - ? 'st' - : b === 2 - ? 'nd' - : b === 3 - ? 'rd' - : 'th'; + ? 'st' + : b === 2 + ? 'nd' + : b === 3 + ? 'rd' + : 'th'; return number + output; }, week: { diff --git a/packages/alloy-compiler/builtins/moment/lang/en-au.js b/packages/alloy-compiler/builtins/moment/lang/en-au.js index 91992f23..3620fa7b 100644 --- a/packages/alloy-compiler/builtins/moment/lang/en-au.js +++ b/packages/alloy-compiler/builtins/moment/lang/en-au.js @@ -60,12 +60,12 @@ ~~((number % 100) / 10) === 1 ? 'th' : b === 1 - ? 'st' - : b === 2 - ? 'nd' - : b === 3 - ? 'rd' - : 'th'; + ? 'st' + : b === 2 + ? 'nd' + : b === 3 + ? 'rd' + : 'th'; return number + output; }, week: { diff --git a/packages/alloy-compiler/builtins/moment/lang/en-ca.js b/packages/alloy-compiler/builtins/moment/lang/en-ca.js index 1f6a7882..6e8b17d5 100644 --- a/packages/alloy-compiler/builtins/moment/lang/en-ca.js +++ b/packages/alloy-compiler/builtins/moment/lang/en-ca.js @@ -60,12 +60,12 @@ ~~((number % 100) / 10) === 1 ? 'th' : b === 1 - ? 'st' - : b === 2 - ? 'nd' - : b === 3 - ? 'rd' - : 'th'; + ? 'st' + : b === 2 + ? 'nd' + : b === 3 + ? 'rd' + : 'th'; return number + output; }, }); diff --git a/packages/alloy-compiler/builtins/moment/lang/en-gb.js b/packages/alloy-compiler/builtins/moment/lang/en-gb.js index 07232e21..d9935c88 100644 --- a/packages/alloy-compiler/builtins/moment/lang/en-gb.js +++ b/packages/alloy-compiler/builtins/moment/lang/en-gb.js @@ -60,12 +60,12 @@ ~~((number % 100) / 10) === 1 ? 'th' : b === 1 - ? 'st' - : b === 2 - ? 'nd' - : b === 3 - ? 'rd' - : 'th'; + ? 'st' + : b === 2 + ? 'nd' + : b === 3 + ? 'rd' + : 'th'; return number + output; }, week: { diff --git a/packages/alloy-compiler/builtins/moment/lang/en-ie.js b/packages/alloy-compiler/builtins/moment/lang/en-ie.js index f82b397c..f0c0f7ca 100644 --- a/packages/alloy-compiler/builtins/moment/lang/en-ie.js +++ b/packages/alloy-compiler/builtins/moment/lang/en-ie.js @@ -60,12 +60,12 @@ ~~((number % 100) / 10) === 1 ? 'th' : b === 1 - ? 'st' - : b === 2 - ? 'nd' - : b === 3 - ? 'rd' - : 'th'; + ? 'st' + : b === 2 + ? 'nd' + : b === 3 + ? 'rd' + : 'th'; return number + output; }, week: { diff --git a/packages/alloy-compiler/builtins/moment/lang/en-il.js b/packages/alloy-compiler/builtins/moment/lang/en-il.js index fac2566b..58193182 100644 --- a/packages/alloy-compiler/builtins/moment/lang/en-il.js +++ b/packages/alloy-compiler/builtins/moment/lang/en-il.js @@ -60,12 +60,12 @@ ~~((number % 100) / 10) === 1 ? 'th' : b === 1 - ? 'st' - : b === 2 - ? 'nd' - : b === 3 - ? 'rd' - : 'th'; + ? 'st' + : b === 2 + ? 'nd' + : b === 3 + ? 'rd' + : 'th'; return number + output; }, }); diff --git a/packages/alloy-compiler/builtins/moment/lang/en-in.js b/packages/alloy-compiler/builtins/moment/lang/en-in.js index b56b3f35..08a4ec40 100644 --- a/packages/alloy-compiler/builtins/moment/lang/en-in.js +++ b/packages/alloy-compiler/builtins/moment/lang/en-in.js @@ -60,12 +60,12 @@ ~~((number % 100) / 10) === 1 ? 'th' : b === 1 - ? 'st' - : b === 2 - ? 'nd' - : b === 3 - ? 'rd' - : 'th'; + ? 'st' + : b === 2 + ? 'nd' + : b === 3 + ? 'rd' + : 'th'; return number + output; }, week: { diff --git a/packages/alloy-compiler/builtins/moment/lang/en-nz.js b/packages/alloy-compiler/builtins/moment/lang/en-nz.js index d9000d0a..2180382f 100644 --- a/packages/alloy-compiler/builtins/moment/lang/en-nz.js +++ b/packages/alloy-compiler/builtins/moment/lang/en-nz.js @@ -60,12 +60,12 @@ ~~((number % 100) / 10) === 1 ? 'th' : b === 1 - ? 'st' - : b === 2 - ? 'nd' - : b === 3 - ? 'rd' - : 'th'; + ? 'st' + : b === 2 + ? 'nd' + : b === 3 + ? 'rd' + : 'th'; return number + output; }, week: { diff --git a/packages/alloy-compiler/builtins/moment/lang/it.js b/packages/alloy-compiler/builtins/moment/lang/it.js index 23cb4739..cfbc574d 100644 --- a/packages/alloy-compiler/builtins/moment/lang/it.js +++ b/packages/alloy-compiler/builtins/moment/lang/it.js @@ -68,8 +68,8 @@ (this.hours() > 1 ? 'lle ' : this.hours() === 0 - ? ' ' - : "ll'") + + ? ' ' + : "ll'") + ']LT' ); default: @@ -78,8 +78,8 @@ (this.hours() > 1 ? 'lle ' : this.hours() === 0 - ? ' ' - : "ll'") + + ? ' ' + : "ll'") + ']LT' ); } diff --git a/packages/alloy-compiler/builtins/moment/lang/ku-kmr.js b/packages/alloy-compiler/builtins/moment/lang/ku-kmr.js new file mode 100644 index 00000000..861027da --- /dev/null +++ b/packages/alloy-compiler/builtins/moment/lang/ku-kmr.js @@ -0,0 +1,125 @@ +//! moment.js locale configuration +//! locale : Northern Kurdish [ku-kmr] +//! authors : Mazlum Özdogan : https://github.com/mergehez + +;(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' + && typeof require === 'function' ? factory(require('/alloy/moment')) : + typeof define === 'function' && define.amd ? define(['../moment'], factory) : + factory(global.moment) +}(this, (function (moment) { 'use strict'; + + //! moment.js locale configuration + + function processRelativeTime(num, withoutSuffix, key, isFuture) { + var format = { + s: ['çend sanîye', 'çend sanîyeyan'], + ss: [num + ' sanîye', num + ' sanîyeyan'], + m: ['deqîqeyek', 'deqîqeyekê'], + mm: [num + ' deqîqe', num + ' deqîqeyan'], + h: ['saetek', 'saetekê'], + hh: [num + ' saet', num + ' saetan'], + d: ['rojek', 'rojekê'], + dd: [num + ' roj', num + ' rojan'], + w: ['hefteyek', 'hefteyekê'], + ww: [num + ' hefte', num + ' hefteyan'], + M: ['mehek', 'mehekê'], + MM: [num + ' meh', num + ' mehan'], + y: ['salek', 'salekê'], + yy: [num + ' sal', num + ' salan'], + }; + return withoutSuffix ? format[key][0] : format[key][1]; + } + // function obliqueNumSuffix(num) { + // if(num.includes(':')) + // num = parseInt(num.split(':')[0]); + // else + // num = parseInt(num); + // return num == 0 || num % 10 == 1 ? 'ê' + // : (num > 10 && num % 10 == 0 ? 'î' : 'an'); + // } + function ezafeNumSuffix(num) { + num = '' + num; + var l = num.substring(num.length - 1), + ll = num.length > 1 ? num.substring(num.length - 2) : ''; + if ( + !(ll == 12 || ll == 13) && + (l == '2' || l == '3' || ll == '50' || l == '70' || l == '80') + ) + return 'yê'; + return 'ê'; + } + + var kuKmr = moment.defineLocale('ku-kmr', { + // According to the spelling rules defined by the work group of Weqfa Mezopotamyayê (Mesopotamia Foundation) + // this should be: 'Kanûna Paşîn_Sibat_Adar_Nîsan_Gulan_Hezîran_Tîrmeh_Tebax_Îlon_Çirîya Pêşîn_Çirîya Paşîn_Kanûna Pêşîn' + // But the names below are more well known and handy + months: 'Rêbendan_Sibat_Adar_Nîsan_Gulan_Hezîran_Tîrmeh_Tebax_Îlon_Cotmeh_Mijdar_Berfanbar'.split( + '_' + ), + monthsShort: 'Rêb_Sib_Ada_Nîs_Gul_Hez_Tîr_Teb_Îlo_Cot_Mij_Ber'.split('_'), + monthsParseExact: true, + weekdays: 'Yekşem_Duşem_Sêşem_Çarşem_Pêncşem_În_Şemî'.split('_'), + weekdaysShort: 'Yek_Du_Sê_Çar_Pên_În_Şem'.split('_'), + weekdaysMin: 'Ye_Du_Sê_Ça_Pê_În_Şe'.split('_'), + meridiem: function (hours, minutes, isLower) { + if (hours < 12) { + return isLower ? 'bn' : 'BN'; + } else { + return isLower ? 'pn' : 'PN'; + } + }, + meridiemParse: /bn|BN|pn|PN/, + longDateFormat: { + LT: 'HH:mm', + LTS: 'HH:mm:ss', + L: 'DD.MM.YYYY', + LL: 'Do MMMM[a] YYYY[an]', + LLL: 'Do MMMM[a] YYYY[an] HH:mm', + LLLL: 'dddd, Do MMMM[a] YYYY[an] HH:mm', + ll: 'Do MMM[.] YYYY[an]', + lll: 'Do MMM[.] YYYY[an] HH:mm', + llll: 'ddd[.], Do MMM[.] YYYY[an] HH:mm', + }, + calendar: { + sameDay: '[Îro di saet] LT [de]', + nextDay: '[Sibê di saet] LT [de]', + nextWeek: 'dddd [di saet] LT [de]', + lastDay: '[Duh di saet] LT [de]', + lastWeek: 'dddd[a borî di saet] LT [de]', + sameElse: 'L', + }, + relativeTime: { + future: 'di %s de', + past: 'berî %s', + s: processRelativeTime, + ss: processRelativeTime, + m: processRelativeTime, + mm: processRelativeTime, + h: processRelativeTime, + hh: processRelativeTime, + d: processRelativeTime, + dd: processRelativeTime, + w: processRelativeTime, + ww: processRelativeTime, + M: processRelativeTime, + MM: processRelativeTime, + y: processRelativeTime, + yy: processRelativeTime, + }, + dayOfMonthOrdinalParse: /\d{1,2}(?:yê|ê|\.)/, + ordinal: function (num, period) { + var p = period.toLowerCase(); + if (p.includes('w') || p.includes('m')) return num + '.'; + + return num + ezafeNumSuffix(num); + }, + week: { + dow: 1, // Monday is the first day of the week. + doy: 4, // The week that contains Jan 4th is the first week of the year. + }, + }); + + return kuKmr; + +}))); diff --git a/packages/alloy-compiler/builtins/moment/lang/lt.js b/packages/alloy-compiler/builtins/moment/lang/lt.js index 9e01f65b..7833578a 100644 --- a/packages/alloy-compiler/builtins/moment/lang/lt.js +++ b/packages/alloy-compiler/builtins/moment/lang/lt.js @@ -35,8 +35,8 @@ return withoutSuffix ? forms(key)[0] : isFuture - ? forms(key)[1] - : forms(key)[2]; + ? forms(key)[1] + : forms(key)[2]; } function special(number) { return number % 10 === 0 || (number > 10 && number < 20); diff --git a/packages/alloy-compiler/builtins/moment/lang/me.js b/packages/alloy-compiler/builtins/moment/lang/me.js index 37a0243f..4398264c 100644 --- a/packages/alloy-compiler/builtins/moment/lang/me.js +++ b/packages/alloy-compiler/builtins/moment/lang/me.js @@ -27,8 +27,8 @@ return number === 1 ? wordKey[0] : number >= 2 && number <= 4 - ? wordKey[1] - : wordKey[2]; + ? wordKey[1] + : wordKey[2]; }, translate: function (number, withoutSuffix, key) { var wordKey = translator.words[key]; diff --git a/packages/alloy-compiler/builtins/moment/lang/nb.js b/packages/alloy-compiler/builtins/moment/lang/nb.js index 5f334533..97ca6920 100644 --- a/packages/alloy-compiler/builtins/moment/lang/nb.js +++ b/packages/alloy-compiler/builtins/moment/lang/nb.js @@ -47,13 +47,13 @@ ss: '%d sekunder', m: 'ett minutt', mm: '%d minutter', - h: 'en time', + h: 'én time', hh: '%d timer', - d: 'en dag', + d: 'én dag', dd: '%d dager', - w: 'en uke', + w: 'én uke', ww: '%d uker', - M: 'en måned', + M: 'én måned', MM: '%d måneder', y: 'ett år', yy: '%d år', diff --git a/packages/alloy-compiler/builtins/moment/lang/nl-be.js b/packages/alloy-compiler/builtins/moment/lang/nl-be.js index 8f4cd776..15261d29 100644 --- a/packages/alloy-compiler/builtins/moment/lang/nl-be.js +++ b/packages/alloy-compiler/builtins/moment/lang/nl-be.js @@ -19,7 +19,7 @@ monthsParse = [ /^jan/i, /^feb/i, - /^maart|mrt.?$/i, + /^(maart|mrt\.?)$/i, /^apr/i, /^mei$/i, /^jun[i.]?$/i, diff --git a/packages/alloy-compiler/builtins/moment/lang/nl.js b/packages/alloy-compiler/builtins/moment/lang/nl.js index fe9bb48c..c4c02a43 100644 --- a/packages/alloy-compiler/builtins/moment/lang/nl.js +++ b/packages/alloy-compiler/builtins/moment/lang/nl.js @@ -19,7 +19,7 @@ monthsParse = [ /^jan/i, /^feb/i, - /^maart|mrt.?$/i, + /^(maart|mrt\.?)$/i, /^apr/i, /^mei$/i, /^jun[i.]?$/i, diff --git a/packages/alloy-compiler/builtins/moment/lang/oc-lnc.js b/packages/alloy-compiler/builtins/moment/lang/oc-lnc.js index c6e92305..424dae89 100644 --- a/packages/alloy-compiler/builtins/moment/lang/oc-lnc.js +++ b/packages/alloy-compiler/builtins/moment/lang/oc-lnc.js @@ -74,12 +74,12 @@ number === 1 ? 'r' : number === 2 - ? 'n' - : number === 3 - ? 'r' - : number === 4 - ? 't' - : 'è'; + ? 'n' + : number === 3 + ? 'r' + : number === 4 + ? 't' + : 'è'; if (period === 'w' || period === 'W') { output = 'a'; } diff --git a/packages/alloy-compiler/builtins/moment/lang/ru.js b/packages/alloy-compiler/builtins/moment/lang/ru.js index 987aed59..c38eb2f8 100644 --- a/packages/alloy-compiler/builtins/moment/lang/ru.js +++ b/packages/alloy-compiler/builtins/moment/lang/ru.js @@ -18,8 +18,8 @@ return num % 10 === 1 && num % 100 !== 11 ? forms[0] : num % 10 >= 2 && num % 10 <= 4 && (num % 100 < 10 || num % 100 >= 20) - ? forms[1] - : forms[2]; + ? forms[1] + : forms[2]; } function relativeTimeWithPlural(number, withoutSuffix, key) { var format = { diff --git a/packages/alloy-compiler/builtins/moment/lang/sv.js b/packages/alloy-compiler/builtins/moment/lang/sv.js index 07ea7a01..c845fb1b 100644 --- a/packages/alloy-compiler/builtins/moment/lang/sv.js +++ b/packages/alloy-compiler/builtins/moment/lang/sv.js @@ -60,12 +60,12 @@ ~~((number % 100) / 10) === 1 ? ':e' : b === 1 - ? ':a' - : b === 2 - ? ':a' - : b === 3 - ? ':e' - : ':e'; + ? ':a' + : b === 2 + ? ':a' + : b === 3 + ? ':e' + : ':e'; return number + output; }, week: { diff --git a/packages/alloy-compiler/builtins/moment/lang/tet.js b/packages/alloy-compiler/builtins/moment/lang/tet.js index afc26918..cb5cfc44 100644 --- a/packages/alloy-compiler/builtins/moment/lang/tet.js +++ b/packages/alloy-compiler/builtins/moment/lang/tet.js @@ -60,12 +60,12 @@ ~~((number % 100) / 10) === 1 ? 'th' : b === 1 - ? 'st' - : b === 2 - ? 'nd' - : b === 3 - ? 'rd' - : 'th'; + ? 'st' + : b === 2 + ? 'nd' + : b === 3 + ? 'rd' + : 'th'; return number + output; }, week: { diff --git a/packages/alloy-compiler/builtins/moment/lang/tlh.js b/packages/alloy-compiler/builtins/moment/lang/tlh.js index 257474d6..9433af90 100644 --- a/packages/alloy-compiler/builtins/moment/lang/tlh.js +++ b/packages/alloy-compiler/builtins/moment/lang/tlh.js @@ -19,10 +19,10 @@ output.indexOf('jaj') !== -1 ? time.slice(0, -3) + 'leS' : output.indexOf('jar') !== -1 - ? time.slice(0, -3) + 'waQ' - : output.indexOf('DIS') !== -1 - ? time.slice(0, -3) + 'nem' - : time + ' pIq'; + ? time.slice(0, -3) + 'waQ' + : output.indexOf('DIS') !== -1 + ? time.slice(0, -3) + 'nem' + : time + ' pIq'; return time; } @@ -32,10 +32,10 @@ output.indexOf('jaj') !== -1 ? time.slice(0, -3) + 'Hu’' : output.indexOf('jar') !== -1 - ? time.slice(0, -3) + 'wen' - : output.indexOf('DIS') !== -1 - ? time.slice(0, -3) + 'ben' - : time + ' ret'; + ? time.slice(0, -3) + 'wen' + : output.indexOf('DIS') !== -1 + ? time.slice(0, -3) + 'ben' + : time + ' ret'; return time; } diff --git a/packages/alloy-compiler/builtins/moment/lang/tzl.js b/packages/alloy-compiler/builtins/moment/lang/tzl.js index bcc90372..a0445040 100644 --- a/packages/alloy-compiler/builtins/moment/lang/tzl.js +++ b/packages/alloy-compiler/builtins/moment/lang/tzl.js @@ -91,8 +91,8 @@ return isFuture ? format[key][0] : withoutSuffix - ? format[key][0] - : format[key][1]; + ? format[key][0] + : format[key][1]; } return tzl; diff --git a/packages/alloy-compiler/builtins/moment/lang/uk.js b/packages/alloy-compiler/builtins/moment/lang/uk.js index 62a826a2..5409df6b 100644 --- a/packages/alloy-compiler/builtins/moment/lang/uk.js +++ b/packages/alloy-compiler/builtins/moment/lang/uk.js @@ -17,8 +17,8 @@ return num % 10 === 1 && num % 100 !== 11 ? forms[0] : num % 10 >= 2 && num % 10 <= 4 && (num % 100 < 10 || num % 100 >= 20) - ? forms[1] - : forms[2]; + ? forms[1] + : forms[2]; } function relativeTimeWithPlural(number, withoutSuffix, key) { var format = { @@ -66,8 +66,8 @@ nounCase = /(\[[ВвУу]\]) ?dddd/.test(format) ? 'accusative' : /\[?(?:минулої|наступної)? ?\] ?dddd/.test(format) - ? 'genitive' - : 'nominative'; + ? 'genitive' + : 'nominative'; return weekdays[nounCase][m.day()]; } function processHoursFunction(str) { diff --git a/packages/alloy-compiler/builtins/moment/lang/x-pseudo.js b/packages/alloy-compiler/builtins/moment/lang/x-pseudo.js index 91ea850b..37c56e95 100644 --- a/packages/alloy-compiler/builtins/moment/lang/x-pseudo.js +++ b/packages/alloy-compiler/builtins/moment/lang/x-pseudo.js @@ -65,12 +65,12 @@ ~~((number % 100) / 10) === 1 ? 'th' : b === 1 - ? 'st' - : b === 2 - ? 'nd' - : b === 3 - ? 'rd' - : 'th'; + ? 'st' + : b === 2 + ? 'nd' + : b === 3 + ? 'rd' + : 'th'; return number + output; }, week: { diff --git a/packages/alloy-compiler/builtins/string.js b/packages/alloy-compiler/builtins/string.js index 0bbde84e..b69127b4 100755 --- a/packages/alloy-compiler/builtins/string.js +++ b/packages/alloy-compiler/builtins/string.js @@ -64,10 +64,7 @@ exports.lcfirst = function (text) { * @param {String} amount Amount to format. * @return {String} Amount formatted as a currency value. */ -exports.formatCurrency = !(OS_MOBILEWEB) ? String.formatCurrency : function (amount) { - var num = isNaN(amount) || amount === '' || amount === null ? 0.00 : amount; - return '$' + parseFloat(num).toFixed(2); -}; +exports.formatCurrency = String.formatCurrency; /** diff --git a/packages/alloy-compiler/lib/ast/controller.js b/packages/alloy-compiler/lib/ast/controller.js index a73ca3eb..2a523935 100644 --- a/packages/alloy-compiler/lib/ast/controller.js +++ b/packages/alloy-compiler/lib/ast/controller.js @@ -6,16 +6,20 @@ var U = require('alloy-utils').utils, var isBaseControllerExportExpression = types.buildMatchMemberExpression('exports.baseController'); -const GENCODE_OPTIONS = { +let GENCODE_OPTIONS = { retainLines: true }; -exports.processController = function (code, file) { +exports.processController = function (code, file, isProduction = false) { var baseController = '', moduleCodes = '', newCode = '', exportSpecifiers = []; + if (isProduction) { + GENCODE_OPTIONS.retainLines = false; + } + try { var ast = babylon.parse(code, { sourceFilename: file, sourceType: 'unambiguous' }); diff --git a/packages/alloy-compiler/lib/compilerUtils.js b/packages/alloy-compiler/lib/compilerUtils.js index 4d84c06d..3820784d 100644 --- a/packages/alloy-compiler/lib/compilerUtils.js +++ b/packages/alloy-compiler/lib/compilerUtils.js @@ -2,7 +2,6 @@ var path = require('path'), os = require('os'), fs = require('fs-extra'), walkSync = require('walk-sync'), - chmodr = require('chmodr'), jsonlint = require('@prantlf/jsonlint'), astController = require('./ast/controller'), sourceMapper = require('./sourceMapper'), @@ -654,12 +653,25 @@ exports.copyWidgetResources = function (resources, resourceDir, widgetId, opts) var dest = path.join(destDir, path.basename(file)); if (!fs.existsSync(destDir)) { fs.mkdirpSync(destDir); - chmodr.sync(destDir, 0o755); } logger.trace('Copying ' + file.yellow + ' --> ' + path.relative(compilerConfig.dir.project, dest).yellow + '...'); U.copyFileSync(source, dest); + + if (path.extname(source) === '.js' && compilerConfig.sourcemap) { + sourceMapper.generateSourceMap({ + target: { + filename: file, + filepath: dest, + }, + data: {}, + origFile: { + filename: file, + filepath: source + } + }, compilerConfig); + } } }); @@ -724,8 +736,9 @@ exports.mergeI18N = function mergeI18N(src, dest, opts) { } if (fs.statSync(srcFile).isDirectory()) { - fs.existsSync(destFile) || fs.mkdirpSync(destFile); - chmodr.sync(destFile, 0o755); + if (!fs.existsSync(destFile)) { + fs.mkdirpSync(destFile); + } return walk(srcFile, destFile); } @@ -893,7 +906,6 @@ function generateConfig(obj) { buildLog.data.cfgHash = hash; // write out the config runtime module fs.mkdirpSync(resourcesBase); - chmodr.sync(resourcesBase, 0o755); // logger.debug('Writing "Resources/' + (platform ? platform + '/' : '') + 'alloy/CFG.js"...'); var output = 'module.exports=' + JSON.stringify(o) + ';'; @@ -903,7 +915,6 @@ function generateConfig(obj) { var baseFolder = path.join(obj.dir.resources, 'alloy'); if (!fs.existsSync(baseFolder)) { fs.mkdirpSync(baseFolder); - chmodr.sync(baseFolder, 0o755); } fs.writeFileSync(path.join(baseFolder, 'CFG.js'), output); } @@ -971,8 +982,9 @@ exports.loadController = function (file, contents) { } } + var isProduction = compilerConfig.alloyConfig?.deploytype === 'production'; // get the base controller for this controller, also process import/export statements - var controller = astController.processController(contents, file); + var controller = astController.processController(contents, file, isProduction); code.controller = controller.code; code.parentControllerName = controller.base; code.es6mods = controller.es6mods; @@ -1043,7 +1055,7 @@ exports.generateCollectionBindingTemplate = function (args) { code += ' if (e && e.fromAdapter) { return; }'; code += ' var opts = ' + handlerFunc + '.opts || {};'; code += ' var models = ' + whereCode + ';'; - code += ' var len = models.length;'; + code += ' var len = models ? models.length : 0;'; code += '<%= pre %>'; code += ' for (var i = 0; i < len; i++) {'; code += ' var <%= localModel %> = models[i];'; @@ -1078,7 +1090,6 @@ exports.updateFiles = function (srcDir, dstDir, opts) { if (!fs.existsSync(dstDir)) { fs.mkdirpSync(dstDir); - chmodr.sync(dstDir, 0o755); } // don't process XML/controller files inside .svn folders (ALOY-839) @@ -1142,7 +1153,6 @@ exports.updateFiles = function (srcDir, dstDir, opts) { } else if (srcStat.isDirectory()) { logger.trace('Creating directory ' + path.relative(opts.rootDir, dst).yellow); fs.mkdirpSync(dst); - chmodr.sync(dst, 0o755); } else { logger.trace('Copying ' + path.join('SRC_DIR', path.relative(srcDir, src)).yellow + ' --> ' + path.relative(opts.rootDir, dst).yellow); diff --git a/packages/alloy-compiler/lib/compilers/component.js b/packages/alloy-compiler/lib/compilers/component.js index 94dadd13..ec328c5f 100644 --- a/packages/alloy-compiler/lib/compilers/component.js +++ b/packages/alloy-compiler/lib/compilers/component.js @@ -78,7 +78,7 @@ class ComponentCompiler extends BaseCompiler { : CU[CONST.DOCROOT_BASECONTROLLER_PROPERTY] || '\'BaseController\''; controllerCode += cCode.controller; template.preCode += cCode.pre; - template.ES6Mod += cCode.es6mods; + template.ES6Mod += cCode.es6mods.trim(); // create generated controller module code for this view/controller or widget const templateName = this.compilationMeta.isWebpack ? 'component.es6.js' : 'component.js'; diff --git a/packages/alloy-compiler/lib/parsers/Alloy.Abstract.Option.js b/packages/alloy-compiler/lib/parsers/Alloy.Abstract.Option.js index 30d8949b..fc1b35bf 100644 --- a/packages/alloy-compiler/lib/parsers/Alloy.Abstract.Option.js +++ b/packages/alloy-compiler/lib/parsers/Alloy.Abstract.Option.js @@ -23,11 +23,13 @@ function parse(node, state, args) { let code = codePush; + // DEVKIT DELTA: emit `const` declarations to avoid implicit-global assignment + // in strict mode. See docs/DEVKIT_DELTAS.md item 3. if (attrName) { if (args.createArgs[attrName]) { - code = `${attrVarName} = ${codePush} - 1`; + code = `const ${attrVarName} = ${codePush} - 1`; } else { - code = `${attrVarName} = undefined; ${codePush}`; + code = `const ${attrVarName} = undefined; ${codePush}`; } } diff --git a/packages/alloy-compiler/lib/parsers/Alloy.Abstract._ItemContainer.js b/packages/alloy-compiler/lib/parsers/Alloy.Abstract._ItemContainer.js index dbf852f3..d74d0ed1 100644 --- a/packages/alloy-compiler/lib/parsers/Alloy.Abstract._ItemContainer.js +++ b/packages/alloy-compiler/lib/parsers/Alloy.Abstract._ItemContainer.js @@ -9,30 +9,37 @@ function fixDefinition(def) { def = _.defaults(def, { children: [], translations: [], - doRemoveNode: def.doRemoveNode || typeof (def.doRemoveNode) === 'undefined', - processOthers: def.processOthers || function () {}, - inViewHierarchy: def.inViewHierarchy || typeof (def.inViewHierarchy) === 'undefined' + doRemoveNode: def.doRemoveNode || typeof(def.doRemoveNode) === 'undefined', + processOthers: def.processOthers || function() {}, + inViewHierarchy: def.inViewHierarchy || typeof(def.inViewHierarchy) === 'undefined' }); return def; } -exports.parse = function (node, state) { +exports.parse = function(node, state) { return require('./base').parse(node, state, parse); }; -function parse(node, state) { - var def = fixDefinition(state.itemContainerDefinition), +function parse(node, state, args) { + var children = U.XML.getElementsFromNodes(node.childNodes), + def = fixDefinition(state.itemContainerDefinition), config = CU.getCompilerConfig(), isAndroid = config && config.alloyConfig && config.alloyConfig.platform === 'android', androidView = null, extras = [], code = ''; - _.each(U.XML.getElementsFromNodes(node.childNodes), function (child) { + // iterate through all children + _.each(children, function(child) { var childArgs = CU.getParserArgs(child, state); + // validate the child element + if (!CU.isNodeForCurrentPlatform(child)) { + return; + } + // do translations - _.each(def.translations, function (t) { + _.each(def.translations, function(t) { if (childArgs.fullname === t.from) { var match = t.to.match(/^(.+)\.(.+)$/); child.nodeName = match[2]; @@ -42,26 +49,27 @@ function parse(node, state) { // process item arrays if present var theNode = CU.validateNodeName(child, _.map(def.children, 'name')); - if (_.find(def.children, c => c.name === theNode)) { + if (_.find(def.children, function(c) { return c.name === theNode; })) { var childState = { parent: {}, itemsArray: CU.generateUniqueId() }; code += CU.generateNodeExtended(child, state, childState); - var prop = _.find(def.children, c => c.name === theNode).property; - extras.push([ prop, childState.itemsArray ]); + var prop = _.find(def.children, function(c) { return c.name === theNode; }).property; + extras.push([prop, childState.itemsArray]); // Only add the extraOptions if they are defined on the child nodes _.each(U.XML.getElementsFromNodes(child.childNodes), (node) => { _.each(state.extraOptions, (varName, name) => { - const attr = _.find(node.attributes, [ 'nodeName', name ]); + const attr = _.find(node.attributes, ['nodeName', name]); if (attr !== undefined) { - extras.push([ name, varName ]); + extras.push([name, varName]); } }); }); + // get rid of the node when we're done so we can pass the current state // back to generateNode() and then process any additional views that // need to be added to the view hierarchy @@ -75,8 +83,8 @@ function parse(node, state) { if (isAndroid) { androidView = CU.generateNodeExtended(child, state, { parent: {}, - post: function (node, state) { - extras.push([ 'androidView', state.parent.symbol ]); + post: function(node, state, args) { + extras.push(['androidView', state.parent.symbol]); } }); code += androidView; diff --git a/packages/alloy-compiler/lib/parsers/Ti.UI.ActivityIndicator.js b/packages/alloy-compiler/lib/parsers/Ti.UI.ActivityIndicator.js new file mode 100644 index 00000000..72ecca31 --- /dev/null +++ b/packages/alloy-compiler/lib/parsers/Ti.UI.ActivityIndicator.js @@ -0,0 +1,9 @@ +var CU = require('../compilerUtils'); + +exports.parse = function(node, state) { + return require('./base').parse(node, state, parse); +}; + +function parse(node, state, args) { + return require('./default').parse(node, state); +} diff --git a/packages/alloy-compiler/lib/parsers/Ti.UI.Column.js b/packages/alloy-compiler/lib/parsers/Ti.UI.Column.js new file mode 100644 index 00000000..72ecca31 --- /dev/null +++ b/packages/alloy-compiler/lib/parsers/Ti.UI.Column.js @@ -0,0 +1,9 @@ +var CU = require('../compilerUtils'); + +exports.parse = function(node, state) { + return require('./base').parse(node, state, parse); +}; + +function parse(node, state, args) { + return require('./default').parse(node, state); +} diff --git a/packages/alloy-compiler/lib/parsers/Ti.UI.MaskedImage.js b/packages/alloy-compiler/lib/parsers/Ti.UI.MaskedImage.js new file mode 100644 index 00000000..72ecca31 --- /dev/null +++ b/packages/alloy-compiler/lib/parsers/Ti.UI.MaskedImage.js @@ -0,0 +1,9 @@ +var CU = require('../compilerUtils'); + +exports.parse = function(node, state) { + return require('./base').parse(node, state, parse); +}; + +function parse(node, state, args) { + return require('./default').parse(node, state); +} diff --git a/packages/alloy-compiler/lib/parsers/Ti.UI.Notification.js b/packages/alloy-compiler/lib/parsers/Ti.UI.Notification.js new file mode 100644 index 00000000..72ecca31 --- /dev/null +++ b/packages/alloy-compiler/lib/parsers/Ti.UI.Notification.js @@ -0,0 +1,9 @@ +var CU = require('../compilerUtils'); + +exports.parse = function(node, state) { + return require('./base').parse(node, state, parse); +}; + +function parse(node, state, args) { + return require('./default').parse(node, state); +} diff --git a/packages/alloy-compiler/lib/parsers/Ti.UI.OptionBar copy.js b/packages/alloy-compiler/lib/parsers/Ti.UI.OptionBar copy.js deleted file mode 100644 index 4fff74e5..00000000 --- a/packages/alloy-compiler/lib/parsers/Ti.UI.OptionBar copy.js +++ /dev/null @@ -1,12 +0,0 @@ -const _ = require('lodash'); -const tiapp = require('../../../tiapp'); -const U = require('../../../utils'); -const MIN_VERSION = '10.0.0'; - -exports.parse = function (node, state) { - const tiappSdkVersion = tiapp.getSdkVersion(); - if (tiapp.version.lt(tiappSdkVersion, MIN_VERSION)) { - U.die(`Ti.UI.OptionBar requires Titanium SDK ${MIN_VERSION}+`); - } - return require('./Ti.UI.ButtonBar').parse(node, state); -}; diff --git a/packages/alloy-compiler/lib/parsers/Ti.UI.OptionBar.js b/packages/alloy-compiler/lib/parsers/Ti.UI.OptionBar.js index 4fff74e5..42655414 100644 --- a/packages/alloy-compiler/lib/parsers/Ti.UI.OptionBar.js +++ b/packages/alloy-compiler/lib/parsers/Ti.UI.OptionBar.js @@ -1,6 +1,5 @@ const _ = require('lodash'); -const tiapp = require('../../../tiapp'); -const U = require('../../../utils'); +const { tiapp, utils: U } = require('alloy-utils'); const MIN_VERSION = '10.0.0'; exports.parse = function (node, state) { diff --git a/packages/alloy-compiler/lib/parsers/Ti.UI.ProgressBar.js b/packages/alloy-compiler/lib/parsers/Ti.UI.ProgressBar.js new file mode 100644 index 00000000..72ecca31 --- /dev/null +++ b/packages/alloy-compiler/lib/parsers/Ti.UI.ProgressBar.js @@ -0,0 +1,9 @@ +var CU = require('../compilerUtils'); + +exports.parse = function(node, state) { + return require('./base').parse(node, state, parse); +}; + +function parse(node, state, args) { + return require('./default').parse(node, state); +} diff --git a/packages/alloy-compiler/lib/parsers/Ti.UI.RefreshControl.js b/packages/alloy-compiler/lib/parsers/Ti.UI.RefreshControl.js new file mode 100644 index 00000000..72ecca31 --- /dev/null +++ b/packages/alloy-compiler/lib/parsers/Ti.UI.RefreshControl.js @@ -0,0 +1,9 @@ +var CU = require('../compilerUtils'); + +exports.parse = function(node, state) { + return require('./base').parse(node, state, parse); +}; + +function parse(node, state, args) { + return require('./default').parse(node, state); +} diff --git a/packages/alloy-compiler/lib/parsers/Ti.UI.Row.js b/packages/alloy-compiler/lib/parsers/Ti.UI.Row.js new file mode 100644 index 00000000..72ecca31 --- /dev/null +++ b/packages/alloy-compiler/lib/parsers/Ti.UI.Row.js @@ -0,0 +1,9 @@ +var CU = require('../compilerUtils'); + +exports.parse = function(node, state) { + return require('./base').parse(node, state, parse); +}; + +function parse(node, state, args) { + return require('./default').parse(node, state); +} diff --git a/packages/alloy-compiler/lib/parsers/Ti.UI.SearchBar.js b/packages/alloy-compiler/lib/parsers/Ti.UI.SearchBar.js new file mode 100644 index 00000000..72ecca31 --- /dev/null +++ b/packages/alloy-compiler/lib/parsers/Ti.UI.SearchBar.js @@ -0,0 +1,9 @@ +var CU = require('../compilerUtils'); + +exports.parse = function(node, state) { + return require('./base').parse(node, state, parse); +}; + +function parse(node, state, args) { + return require('./default').parse(node, state); +} diff --git a/packages/alloy-compiler/lib/parsers/Ti.UI.Shortcut.js b/packages/alloy-compiler/lib/parsers/Ti.UI.Shortcut.js new file mode 100644 index 00000000..72ecca31 --- /dev/null +++ b/packages/alloy-compiler/lib/parsers/Ti.UI.Shortcut.js @@ -0,0 +1,9 @@ +var CU = require('../compilerUtils'); + +exports.parse = function(node, state) { + return require('./base').parse(node, state, parse); +}; + +function parse(node, state, args) { + return require('./default').parse(node, state); +} diff --git a/packages/alloy-compiler/lib/parsers/Ti.UI.ShortcutItem.js b/packages/alloy-compiler/lib/parsers/Ti.UI.ShortcutItem.js new file mode 100644 index 00000000..72ecca31 --- /dev/null +++ b/packages/alloy-compiler/lib/parsers/Ti.UI.ShortcutItem.js @@ -0,0 +1,9 @@ +var CU = require('../compilerUtils'); + +exports.parse = function(node, state) { + return require('./base').parse(node, state, parse); +}; + +function parse(node, state, args) { + return require('./default').parse(node, state); +} diff --git a/packages/alloy-compiler/lib/parsers/Ti.UI.iPhone.NavigationGroup.js b/packages/alloy-compiler/lib/parsers/Ti.UI.iPhone.NavigationGroup.js deleted file mode 100755 index 470201a4..00000000 --- a/packages/alloy-compiler/lib/parsers/Ti.UI.iPhone.NavigationGroup.js +++ /dev/null @@ -1,58 +0,0 @@ -var styler = require('../styler'), - U = require('alloy-utils').utils, - CU = require('../compilerUtils'), - tiapp = require('alloy-utils').tiapp, - logger = require('alloy-utils').logger; - -var DEPRECATED_VERSION = '3.1.3'; - -exports.parse = function (node, state) { - return require('./base').parse(node, state, parse); -}; - -function parse(node, state) { - if (tiapp.version.gte(tiapp.getSdkVersion(), DEPRECATED_VERSION)) { - logger.warn([ - 'Ti.UI.iPhone.NavigationGroup (line ' + node.lineNumber + ') is deprecated as of Titanium ' + DEPRECATED_VERSION, - 'Use Ti.UI.NavigationWindow instead' - ]); - } - - var children = U.XML.getElementsFromNodes(node.childNodes), - err = [ 'NavigationGroup must have only one child element, which must be a Window' ], - code = ''; - - // NavigationGroup must have 1 window as a child - if (children.length !== 1) { - U.die(err); - } - - var child = children[0], - childArgs = CU.getParserArgs(child), - theNode = CU.validateNodeName(child, 'Ti.UI.Window'), - windowSymbol; - - // generate the code for the Window first - if (theNode) { - code += CU.generateNodeExtended(child, state, { - parent: {}, - post: function (node, state) { - windowSymbol = state.parent.symbol; - } - }); - } else { - err.unshift('Invalid NavigationGroup child "' + childArgs.fullname + '"'); - U.die(err); - } - - // create navgroup with window - state.extraStyle = styler.createVariableStyle('window', windowSymbol); - code += require('./default').parse(node, state).code; - - // Update the parsing state - return { - parent: {}, - styles: state.styles, - code: code - }; -} diff --git a/packages/alloy-compiler/lib/sourceMapper.js b/packages/alloy-compiler/lib/sourceMapper.js index e00b156a..2e4a9d4d 100644 --- a/packages/alloy-compiler/lib/sourceMapper.js +++ b/packages/alloy-compiler/lib/sourceMapper.js @@ -4,7 +4,6 @@ */ var SM = require('source-map'), fs = require('fs-extra'), - chmodr = require('chmodr'), path = require('path'), babylon = require('@babel/parser'), babel = require('@babel/core'), @@ -62,9 +61,20 @@ exports.generateCodeAndSourceMap = function (generator, compileConfig) { var relativeOutfile = path.relative(compileConfig.dir.project, outfile); var markers = _.map(data, (v, k) => k); var mapper = new SM.SourceMapGenerator({ - file: `${compileConfig.dir.project}/${relativeOutfile}`, + file: path.join(compileConfig.dir.project, relativeOutfile), sourceRoot: compileConfig.dir.project }); + // try to lookup the filename, falling back to the output file if we can't determine it + let filename; + if (data.__MAPMARKER_CONTROLLER_CODE__ && data.__MAPMARKER_CONTROLLER_CODE__.filename) { + filename = data.__MAPMARKER_CONTROLLER_CODE__.filename; + } else if (data.__MAPMARKER_ALLOY_JS__ && data.__MAPMARKER_ALLOY_JS__.filename) { + filename = data.__MAPMARKER_ALLOY_JS__.filename; + } else if (data.__MAPMARKER_NONCONTROLLER__ && data.__MAPMARKER_NONCONTROLLER__.filename) { + filename = data.__MAPMARKER_NONCONTROLLER__.filename; + } else { + filename = target.filename; + } // the line counter and code string for the generated file var genMap = { count: 1, @@ -126,7 +136,8 @@ exports.generateCodeAndSourceMap = function (generator, compileConfig) { plugins: [ [ require('./ast/builtins-plugin'), compileConfig ], [ require('./ast/optimizer-plugin'), compileConfig.alloyConfig ] - ] + ], + filename }); if (compileConfig.sourcemap) { // Tell babel to retain the lines so they stay correct (columns go wacky, but OH WELL) @@ -144,7 +155,6 @@ exports.generateCodeAndSourceMap = function (generator, compileConfig) { // write the generated controller code fs.mkdirpSync(path.dirname(outfile)); - chmodr.sync(path.dirname(outfile), 0o755); fs.writeFileSync(outfile, outputResult.code.toString()); logger.info(' created: "' + relativeOutfile + '"'); @@ -154,7 +164,6 @@ exports.generateCodeAndSourceMap = function (generator, compileConfig) { outfile = path.join(mapDir, relativeOutfile) + '.' + CONST.FILE_EXT.MAP; relativeOutfile = path.relative(compileConfig.dir.project, outfile); fs.mkdirpSync(path.dirname(outfile)); - chmodr.sync(path.dirname(outfile), 0o755); fs.writeFileSync(outfile, JSON.stringify(sourceMap)); } }; @@ -165,7 +174,7 @@ exports.generateSourceMap = function (generator, compileConfig) { var origFile = generator.origFile; var markers = _.map(data, (v, k) => k); var mapper = new SM.SourceMapGenerator({ - file: `${compileConfig.dir.project}/${target.filename}`, + file: path.join(compileConfig.dir.project, target.filename), sourceRoot: compileConfig.dir.project }); var genMap = { @@ -229,7 +238,6 @@ exports.generateSourceMap = function (generator, compileConfig) { var mapDir = path.join(compileConfig.dir.project, CONST.DIR.MAP); var outfile = path.join(mapDir, relativeOutfile) + '.' + CONST.FILE_EXT.MAP; fs.mkdirpSync(path.dirname(outfile)); - chmodr.sync(path.dirname(outfile), 0o755); fs.writeFileSync(outfile, JSON.stringify(mapper.toJSON())); logger.debug(' map: "' + outfile + '"'); }; diff --git a/packages/alloy-compiler/package.json b/packages/alloy-compiler/package.json index 9ff3c5a0..e7062520 100644 --- a/packages/alloy-compiler/package.json +++ b/packages/alloy-compiler/package.json @@ -1,36 +1,35 @@ { "name": "alloy-compiler", - "version": "0.2.7", + "version": "1.0.0-beta.0", "description": "Compiler for Alloy components", "main": "lib/index.js", "keywords": [ "alloy", "compiler" ], - "author": "Axway Appcelerator", + "author": "TiDev, Inc. ", "license": "Apache-2.0", - "homepage": "https://github.com/appcelerator/alloy-devkit/tree/develop/packages/alloy-compiler#readme", + "homepage": "https://github.com/tidev/alloy-devkit/tree/develop/packages/alloy-compiler#readme", "repository": { "type": "git", - "url": "git+https://github.com/appcelerator/alloy-devkit.git" + "url": "git+https://github.com/tidev/alloy-devkit.git" }, "dependencies": { - "@babel/core": "^7.9.6", - "@babel/generator": "^7.9.6", - "@babel/parser": "^7.9.6", - "@babel/traverse": "^7.9.6", - "@babel/types": "^7.9.6", + "@babel/core": "^7.19.6", + "@babel/generator": "^7.20.0", + "@babel/parser": "^7.20.0", + "@babel/traverse": "^7.18.15", + "@babel/types": "^7.20.0", "@prantlf/jsonlint": "^16.0.0", "@xmldom/xmldom": "^0.8.10", - "alloy-utils": "^0.2.7", - "chmodr": "^1.2.0", - "fs-extra": "^9.0.0", - "lodash": "^4.17.15", - "node.extend": "^2.0.2", - "source-map": "^0.7.3", + "alloy-utils": "^1.0.0-beta.0", + "fs-extra": "^10.1.0", + "lodash": "^4.17.21", + "node.extend": "^2.0.3", + "source-map": "^0.7.4", "walk-sync": "^2.0.2" }, "engines": { - "node": ">=10.0.0" + "node": ">=20.18.1" } } diff --git a/packages/alloy-compiler/test/unit/__snapshots__/parsers.spec.js.snap b/packages/alloy-compiler/test/unit/__snapshots__/parsers.spec.js.snap new file mode 100644 index 00000000..49f2c3d6 --- /dev/null +++ b/packages/alloy-compiler/test/unit/__snapshots__/parsers.spec.js.snap @@ -0,0 +1,53 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`wave 1 parsers compiles a view using wave-1 tags without error: wave1-parsers 1`] = ` +"$.__views[\\"wave1-parsers\\"] = Ti.UI.createWindow( +{id:\\"wave1-parsers\\",} +); +$.__views[\\"wave1-parsers\\"] && $.addTopLevelView($.__views[\\"wave1-parsers\\"]); +$.__views[\\"__alloyId0\\"] = Ti.UI.createActivityIndicator( +{id:\\"__alloyId0\\",} +); +$.__views[\\"wave1-parsers\\"].add($.__views[\\"__alloyId0\\"]); +$.__views[\\"__alloyId1\\"] = Ti.UI.createProgressBar( +{id:\\"__alloyId1\\",} +); +$.__views[\\"wave1-parsers\\"].add($.__views[\\"__alloyId1\\"]); +$.__views[\\"__alloyId2\\"] = Ti.UI.createRefreshControl( +{id:\\"__alloyId2\\",} +); +$.__views[\\"wave1-parsers\\"].add($.__views[\\"__alloyId2\\"]); +$.__views[\\"__alloyId3\\"] = Ti.UI.createSearchBar( +{id:\\"__alloyId3\\",} +); +$.__views[\\"wave1-parsers\\"].add($.__views[\\"__alloyId3\\"]); +$.__views[\\"__alloyId4\\"] = Ti.UI.createView( +{id:\\"__alloyId4\\",} +); +$.__views[\\"wave1-parsers\\"].add($.__views[\\"__alloyId4\\"]); +$.__views[\\"__alloyId5\\"] = Ti.UI.createColumn( +{id:\\"__alloyId5\\",} +); +$.__views[\\"__alloyId4\\"].add($.__views[\\"__alloyId5\\"]); +$.__views[\\"__alloyId6\\"] = Ti.UI.createRow( +{id:\\"__alloyId6\\",} +); +$.__views[\\"__alloyId5\\"].add($.__views[\\"__alloyId6\\"]); +$.__views[\\"__alloyId7\\"] = Ti.UI.createMaskedImage( +{id:\\"__alloyId7\\",} +); +$.__views[\\"wave1-parsers\\"].add($.__views[\\"__alloyId7\\"]); +$.__views[\\"__alloyId8\\"] = Ti.UI.createNotification( +{id:\\"__alloyId8\\",} +); +$.__views[\\"wave1-parsers\\"].add($.__views[\\"__alloyId8\\"]); +$.__views[\\"__alloyId9\\"] = Ti.UI.createShortcut( +{id:\\"__alloyId9\\",} +); +$.__views[\\"wave1-parsers\\"].add($.__views[\\"__alloyId9\\"]); +$.__views[\\"__alloyId10\\"] = Ti.UI.createShortcutItem( +{id:\\"__alloyId10\\",} +); +$.__views[\\"__alloyId9\\"].add($.__views[\\"__alloyId10\\"]); +exports.destroy = function () {};" +`; diff --git a/packages/alloy-compiler/test/unit/__snapshots__/smoke.spec.js.snap b/packages/alloy-compiler/test/unit/__snapshots__/smoke.spec.js.snap new file mode 100644 index 00000000..62f2b865 --- /dev/null +++ b/packages/alloy-compiler/test/unit/__snapshots__/smoke.spec.js.snap @@ -0,0 +1,75 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`smoke: end-to-end compile of test-app fixture compiles the index component end-to-end: component 1`] = ` +"var Alloy = require('/alloy'), + Backbone = Alloy.Backbone, + _ = Alloy._; + + + + +function __processArg(obj, key) { + var arg = null; + if (obj) { + arg = obj[key] || null; + } + return arg; +} + +function Controller() { + + require('/alloy/controllers/' + 'BaseController').apply(this, Array.prototype.slice.call(arguments)); + this.__controllerPath = 'index'; + this.args = arguments[0] || {}; + + if (arguments[0]) { + var __parentSymbol = __processArg(arguments[0], '__parentSymbol'); + var $model = __processArg(arguments[0], '$model'); + var __itemTemplate = __processArg(arguments[0], '__itemTemplate'); + } + var $ = this; + var exports = {}; + var __defers = {}; + + // Generated code that must be executed before all UI and/or + // controller code. One example is all model and collection + // declarations from markup. + + + // Generated UI code + $.__views[\\"index\\"] = Ti.UI.createWindow( +{backgroundColor:\\"#fff\\",fullscreen:false,exitOnClose:true,id:\\"index\\",} +); +$.__views[\\"index\\"] && $.addTopLevelView($.__views[\\"index\\"]); +$.__views[\\"label\\"] = Ti.UI.createLabel( +{color:\\"#000\\",font:{fontSize:\\"18dp\\",fontWeight:\\"bold\\",},height:Ti.UI.SIZE,width:Ti.UI.SIZE,text:'Hello, World!',id:\\"label\\",} +); +$.__views[\\"index\\"].add($.__views[\\"label\\"]); +sayHello?$.addListener($.__views[\\"label\\"],'click',sayHello):__defers['$.__views[\\"label\\"]!click!sayHello']=true;exports.destroy = function () {}; + + // make all IDed elements in $.__views available right on the $ in a + // controller's internal code. Externally the IDed elements will + // be accessed with getView(). + _.extend($, $.__views); + + // Controller code directly from the developer's controller file + $.index.open(); + + function sayHello() { + alert('Hello World$'); + } + + // Generated code that must be executed after all UI and + // controller code. One example deferred event handlers whose + // functions are not defined until after the controller code + // is executed. + __defers['$.__views[\\"label\\"]!click!sayHello'] && $.addListener($.__views[\\"label\\"],'click',sayHello); + + // Extend the $ instance with all functions and properties + // defined on the exports object. + _.extend($, exports); +} + +module.exports = Controller; +" +`; diff --git a/packages/alloy-compiler/test/unit/fixtures/test-app/app/views/wave1-parsers.xml b/packages/alloy-compiler/test/unit/fixtures/test-app/app/views/wave1-parsers.xml new file mode 100644 index 00000000..4d5c3ff7 --- /dev/null +++ b/packages/alloy-compiler/test/unit/fixtures/test-app/app/views/wave1-parsers.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/packages/alloy-compiler/test/unit/parsers.spec.js b/packages/alloy-compiler/test/unit/parsers.spec.js new file mode 100644 index 00000000..9f7cef3e --- /dev/null +++ b/packages/alloy-compiler/test/unit/parsers.spec.js @@ -0,0 +1,35 @@ +const { setupCompilerFactory, resolveComponentPath } = require('./utils'); + +const factory = setupCompilerFactory(); + +describe('wave 1 parsers', () => { + const tags = [ + 'ActivityIndicator', + 'Column', + 'MaskedImage', + 'Notification', + 'ProgressBar', + 'RefreshControl', + 'Row', + 'SearchBar', + 'Shortcut', + 'ShortcutItem' + ]; + + it('compiles a view using wave-1 tags without error', () => { + expect.assertions(1); + const compiler = factory.createCompiler('view'); + const result = compiler.compile({ + file: resolveComponentPath('views', 'wave1-parsers.xml') + }); + expect(result.viewCode).toMatchSnapshot('wave1-parsers'); + }); + + for (const tag of tags) { + it(`registers parser for Ti.UI.${tag}`, () => { + expect.assertions(1); + const parser = require(`../../lib/parsers/Ti.UI.${tag}`); + expect(typeof parser.parse).toBe('function'); + }); + } +}); diff --git a/packages/alloy-compiler/test/unit/smoke.spec.js b/packages/alloy-compiler/test/unit/smoke.spec.js new file mode 100644 index 00000000..488f1a8d --- /dev/null +++ b/packages/alloy-compiler/test/unit/smoke.spec.js @@ -0,0 +1,16 @@ +const { setupCompilerFactory, resolveComponentPath } = require('./utils'); + +describe('smoke: end-to-end compile of test-app fixture', () => { + const factory = setupCompilerFactory(); + + it('compiles the index component end-to-end', () => { + expect.assertions(1); + + const componentCompiler = factory.createCompiler('component'); + const result = componentCompiler.compile({ + file: resolveComponentPath('controllers', 'index.js') + }); + + expect(result.code).toMatchSnapshot('component'); + }); +}); diff --git a/packages/alloy-utils/lib/constants.js b/packages/alloy-utils/lib/constants.js index fe6f3163..0aacf473 100644 --- a/packages/alloy-utils/lib/constants.js +++ b/packages/alloy-utils/lib/constants.js @@ -29,7 +29,7 @@ exports.SKIP_EVENT_HANDLING = [ 'Ti.UI.ListItem', 'Alloy.Abstract.ItemTemplate' exports.ADAPTERS = [ 'localStorage', 'properties', 'sql' ]; exports.CONTROLLER_NODES = [ 'Alloy.Require', 'Alloy.Widget' ]; exports.DEFAULT_BACKBONE_VERSION = '0.9.2'; -exports.SUPPORTED_BACKBONE_VERSIONS = [ '0.9.2', '1.1.2', '1.3.3', '1.4.0' ]; +exports.SUPPORTED_BACKBONE_VERSIONS = [ '0.9.2', '1.1.2', '1.3.3', '1.4.0', '1.6.0' ]; // property names exports.CLASS_PROPERTY = 'classes'; @@ -134,8 +134,7 @@ var NS_ALLOY = 'Alloy', NS_TI_MEDIA = 'Ti.Media', NS_TI_UI_IOS = 'Ti.UI.iOS', NS_TI_UI_IPAD = 'Ti.UI.iPad', - NS_TI_UI_IPHONE = 'Ti.UI.iPhone', - NS_TI_UI_WINDOWS = 'Ti.UI.Windows'; + NS_TI_UI_IPHONE = 'Ti.UI.iPhone'; exports.IMPLICIT_NAMESPACES = { // Alloy @@ -201,12 +200,6 @@ exports.IMPLICIT_NAMESPACES = { NavigationGroup: NS_TI_UI_IPHONE, StatusBar: NS_TI_UI_IPHONE, - // Ti.UI.Windows - CommandBar: NS_TI_UI_WINDOWS, - AppBarButton: NS_TI_UI_WINDOWS, - AppBarToggleButton: NS_TI_UI_WINDOWS, - AppBarSeparator: NS_TI_UI_WINDOWS, - // Ti.UI.Window LeftNavButton: 'Ti.UI.Window', RightNavButton: 'Ti.UI.Window', diff --git a/packages/alloy-utils/lib/utils.js b/packages/alloy-utils/lib/utils.js index d6bfb08a..6f487d2d 100644 --- a/packages/alloy-utils/lib/utils.js +++ b/packages/alloy-utils/lib/utils.js @@ -2,7 +2,6 @@ var path = require('path'), fs = require('fs-extra'), - chmodr = require('chmodr'), crypto = require('crypto'), util = require('util'), jsonlint = require('@prantlf/jsonlint'), @@ -163,7 +162,6 @@ exports.getAndValidateProjectPaths = function (argPath, opts) { var appjs = path.join(paths.resources, 'app.js'); if (!fs.existsSync(appjs)) { fs.mkdirpSync(paths.resources); - chmodr.sync(paths.resources, 0o755); fs.writeFileSync(appjs, ''); } @@ -419,7 +417,6 @@ exports.copyFileSync = function (srcFile, destFile) { exports.ensureDir = function (p) { if (!fs.existsSync(p)) { fs.mkdirpSync(p); - chmodr.sync(p, 0o755); } }; diff --git a/packages/alloy-utils/package.json b/packages/alloy-utils/package.json index 4fd86ef3..056c2ed9 100644 --- a/packages/alloy-utils/package.json +++ b/packages/alloy-utils/package.json @@ -1,6 +1,6 @@ { "name": "alloy-utils", - "version": "0.2.7", + "version": "1.0.0-beta.0", "description": "Common utils for Alloy", "main": "lib/index.js", "keywords": [ @@ -8,26 +8,25 @@ "common", "utils" ], - "author": "Axway Appcelerator", + "author": "TiDev, Inc. ", "license": "Apache-2.0", - "homepage": "https://github.com/appcelerator/alloy-devkit/tree/develop/packages/alloy-utils#readme", + "homepage": "https://github.com/tidev/alloy-devkit/tree/develop/packages/alloy-utils#readme", "repository": { "type": "git", - "url": "git+https://github.com/appcelerator/alloy-devkit.git" + "url": "git+https://github.com/tidev/alloy-devkit.git" }, "dependencies": { - "@babel/code-frame": "^7.8.3", - "chmodr": "^1.2.0", + "@babel/code-frame": "^7.18.6", + "@prantlf/jsonlint": "^16.0.0", + "@xmldom/xmldom": "^0.8.10", "colors": "^1.4.0", - "fs-extra": "^9.0.0", + "fs-extra": "^10.1.0", "global-paths": "^1.0.0", - "jsonlint": "^1.6.3", - "lodash": "^4.17.15", - "moment": "^2.24.0", - "resolve": "^1.12.0", - "xmldom": "^0.6.0" + "lodash": "^4.17.21", + "moment": "^2.30.1", + "resolve": "^1.22.1" }, "engines": { - "node": ">=10.0.0" + "node": ">=20.18.1" } }