alloy 3.0.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/.github/workflows/cla.yaml +1 -1
  2. package/Alloy/alloy.js +7 -4
  3. package/Alloy/builtins/social.js +1 -1
  4. package/Alloy/builtins/string.js +1 -4
  5. package/Alloy/commands/compile/Orphanage.js +1 -2
  6. package/Alloy/commands/compile/README.md +1 -1
  7. package/Alloy/commands/compile/ast/builtins-plugin.js +1 -1
  8. package/Alloy/commands/compile/ast/controller.js +52 -27
  9. package/Alloy/commands/compile/compilerUtils.js +24 -11
  10. package/Alloy/commands/compile/index.js +211 -62
  11. package/Alloy/commands/compile/parsers/Alloy.Abstract._BackboneClass.js +3 -2
  12. package/Alloy/commands/compile/parsers/Alloy.Require.js +10 -4
  13. package/Alloy/commands/compile/parsers/Ti.UI.ActivityIndicator.js +9 -0
  14. package/Alloy/commands/compile/parsers/Ti.UI.Column.js +9 -0
  15. package/Alloy/commands/compile/parsers/Ti.UI.MaskedImage.js +9 -0
  16. package/Alloy/commands/compile/parsers/Ti.UI.Notification.js +9 -0
  17. package/Alloy/commands/compile/parsers/Ti.UI.ProgressBar.js +9 -0
  18. package/Alloy/commands/compile/parsers/Ti.UI.RefreshControl.js +9 -0
  19. package/Alloy/commands/compile/parsers/Ti.UI.Row.js +9 -0
  20. package/Alloy/commands/compile/parsers/Ti.UI.SearchBar.js +9 -0
  21. package/Alloy/commands/compile/parsers/Ti.UI.Shortcut.js +9 -0
  22. package/Alloy/commands/compile/parsers/Ti.UI.ShortcutItem.js +9 -0
  23. package/Alloy/commands/compile/sourceMapper.js +0 -16
  24. package/Alloy/commands/compile/styler.js +101 -58
  25. package/Alloy/commands/db/index.js +76 -0
  26. package/Alloy/commands/generate/targets/jmk.js +1 -1
  27. package/Alloy/commands/generate/targets/style.js +1 -1
  28. package/Alloy/commands/generate/targets/widget.js +2 -2
  29. package/Alloy/commands/new/index.js +1 -1
  30. package/Alloy/commands/purgetss/index.js +5 -0
  31. package/Alloy/common/constants.js +2 -11
  32. package/Alloy/lib/alloy/sync/localStorage.js +0 -8
  33. package/Alloy/lib/alloy/sync/sql.js +12 -9
  34. package/Alloy/plugin/plugin.py +1 -123
  35. package/Alloy/template/lib/alloy.js +7 -8
  36. package/Alloy/tiapp.js +18 -0
  37. package/CHANGELOG.md +6 -0
  38. package/README.md +4 -0
  39. package/package.json +1 -1
  40. package/platforms/windows/index.js +0 -4
  41. package/samples/apps/advanced/complex_styling/config.json +1 -4
  42. package/samples/apps/advanced/custom_tss_queries/styles/index.tss +0 -6
  43. package/samples/apps/advanced/device_query/specs/index.js +1 -12
  44. package/samples/apps/advanced/device_query/styles/index.tss +0 -12
  45. package/samples/apps/advanced/form_factor/views/index.xml +1 -7
  46. package/samples/apps/advanced/inheritance/controllers/index.js +4 -8
  47. package/samples/apps/advanced/inheritance/specs/baseDialog.js +2 -2
  48. package/samples/apps/advanced/master_detail/specs/row.js +3 -3
  49. package/samples/apps/advanced/proxy_property_requires/widgets/com.foo.widget/views/section.xml +3 -3
  50. package/samples/apps/advanced/proxy_property_requires/widgets/com.foo.widget/widget.json +2 -2
  51. package/samples/apps/advanced/require_children/widgets/alloy.container/widget.json +2 -2
  52. package/samples/apps/advanced/themes/specs/dialog.js +1 -18
  53. package/samples/apps/advanced/themes/specs/index.js +1 -45
  54. package/samples/apps/advanced/theming_widgets/widgets/starrating/widget.json +2 -2
  55. package/samples/apps/basics/builtins/specs/index.js +2 -2
  56. package/samples/apps/basics/config_json/config.json +1 -4
  57. package/samples/apps/basics/global_style/specs/item.js +2 -2
  58. package/samples/apps/basics/simple/specs/index.js +2 -2
  59. package/samples/apps/models/binding_tableview/controllers/tab_1.js +2 -2
  60. package/samples/apps/models/binding_tableview/controllers/tab_2.js +2 -2
  61. package/samples/apps/models/binding_tableview/controllers/tab_3.js +2 -2
  62. package/samples/apps/models/binding_tableview/controllers/tab_4.js +2 -2
  63. package/samples/apps/ui/buttonbar/views/index.xml +1 -1
  64. package/samples/apps/ui/switch/views/index.xml +2 -2
  65. package/samples/apps/widgets/basic/widgets/com.foo.widget/widget.json +2 -2
  66. package/samples/apps/widgets/complex/widgets/com.appcelerator.loading/widget.json +1 -1
  67. package/samples/apps/widgets/complex/widgets/com.testing.searchForBooks/widget.json +1 -1
  68. package/samples/apps/widgets/models/widgets/alloy.datatable/widget.json +1 -1
  69. package/samples/apps/widgets/wpath/widgets/com.test.hellobutton/widget.json +1 -1
  70. package/test/specs/new.js +0 -2
  71. package/test/specs/optimizer.js +0 -2
  72. package/test/specs/purgetss.js +74 -0
  73. package/test/specs/require.js +94 -0
  74. package/test/specs/styler.js +271 -0
@@ -4,9 +4,9 @@
4
4
  <Switch/>
5
5
 
6
6
  <!-- switch with some platform-specific styling -->
7
- <Switch class="titles" platform="android,mobileweb"/>
7
+ <Switch class="titles" platform="android"/>
8
8
 
9
9
  <!-- an android checkbox -->
10
10
  <Switch class="checkbox" platform="android"/>
11
11
  </Window>
12
- </Alloy>
12
+ </Alloy>
@@ -9,6 +9,6 @@
9
9
  "min-alloy-version": "1.0",
10
10
  "min-titanium-version":"2.1",
11
11
  "tags":"",
12
- "platforms":"android,ios,mobileweb,windows",
12
+ "platforms":"android,ios",
13
13
  "dependencies": {}
14
- }
14
+ }
@@ -9,6 +9,6 @@
9
9
  "min-alloy-version": "0.1.16",
10
10
  "min-titanium-version":"2.0",
11
11
  "tags":"utility,loading,progress",
12
- "platforms":"android,ios,mobileweb,windows",
12
+ "platforms":"android,ios",
13
13
  "dependencies": {}
14
14
  }
@@ -9,7 +9,7 @@
9
9
  "min-alloy-version": "0.1.16",
10
10
  "min-titanium-version":"2.0",
11
11
  "tags":"utility,google,search",
12
- "platforms":"android,ios,mobileweb,windows",
12
+ "platforms":"android,ios",
13
13
  "dependencies": {
14
14
  "com.appcelerator.loading":"1.0"
15
15
 
@@ -9,6 +9,6 @@
9
9
  "min-alloy-version": "1.0",
10
10
  "min-titanium-version":"3.0",
11
11
  "tags":"",
12
- "platforms":"android,ios,mobileweb,windows",
12
+ "platforms":"android,ios",
13
13
  "dependencies": {}
14
14
  }
@@ -9,6 +9,6 @@
9
9
  "min-alloy-version": "0.2.35",
10
10
  "min-titanium-version":"2.1",
11
11
  "tags":"",
12
- "platforms":"android,ios,mobileweb,windows",
12
+ "platforms":"android,ios",
13
13
  "dependencies": {}
14
14
  }
package/test/specs/new.js CHANGED
@@ -56,10 +56,8 @@ var TO_BE_CREATED = [
56
56
  path.join('app','assets'),
57
57
  path.join('app','assets','android'),
58
58
  path.join('app','assets','iphone'),
59
- path.join('app','assets','mobileweb'),
60
59
  path.join('plugins'),
61
60
  path.join('plugins','ti.alloy'),
62
- path.join('plugins','ti.alloy','plugin.py'),
63
61
  path.join('plugins','ti.alloy','hooks'),
64
62
  path.join('plugins','ti.alloy','hooks','alloy.js'),
65
63
  path.join('tiapp.xml')
@@ -88,9 +88,7 @@ var tests = [
88
88
  var platforms = {};
89
89
  var platformsDir = path.join(__dirname,'..','..','platforms');
90
90
  _.each(CONST.PLATFORMS, function(p) {
91
- if (p != "mobileweb" && p != "windows") {
92
91
  platforms[p] = require(path.join(platformsDir,p,'index'));
93
- }
94
92
  });
95
93
  // The alloy command test suite
96
94
  describe('optimizer.js', function() {
@@ -0,0 +1,74 @@
1
+ var fs = require('fs'),
2
+ os = require('os'),
3
+ path = require('path'),
4
+ spawnSync = require('child_process').spawnSync;
5
+
6
+ describe('alloy purgetss deprecation', function() {
7
+ var directory, callsFile, outputFile;
8
+
9
+ beforeEach(function() {
10
+ directory = fs.mkdtempSync(path.join(os.tmpdir(), 'alloy-purgetss-'));
11
+ callsFile = path.join(directory, 'calls.jsonl');
12
+ outputFile = path.join(directory, 'output.txt');
13
+ var script = path.join(directory, 'fake-purgetss.js');
14
+ fs.writeFileSync(script, '#!' + process.execPath + '\n' +
15
+ 'const fs = require("fs");\n' +
16
+ 'fs.appendFileSync(process.env.PURGETSS_TEST_CALLS, JSON.stringify(process.argv.slice(2)) + "\\n");\n' +
17
+ 'console.log("PurgeTSS test executable ran");\n');
18
+ if (process.platform === 'win32') {
19
+ fs.writeFileSync(path.join(directory, 'purgetss.cmd'), '@"' + process.execPath + '" "' + script + '" %*\r\n');
20
+ } else {
21
+ fs.copyFileSync(script, path.join(directory, 'purgetss'));
22
+ fs.chmodSync(path.join(directory, 'purgetss'), 0o755);
23
+ }
24
+ });
25
+
26
+ afterEach(function() {
27
+ fs.rmSync(directory, { recursive: true, force: true });
28
+ });
29
+
30
+ function run(args) {
31
+ var descriptor = fs.openSync(outputFile, 'w');
32
+ var result;
33
+ try {
34
+ result = spawnSync(process.execPath, [path.resolve(__dirname, '../../bin/alloy'), '-n'].concat(args), {
35
+ cwd: directory,
36
+ env: Object.assign({}, process.env, { PATH: directory, PURGETSS_TEST_CALLS: callsFile }),
37
+ stdio: ['ignore', descriptor, descriptor],
38
+ timeout: 5000
39
+ });
40
+ } finally {
41
+ fs.closeSync(descriptor);
42
+ }
43
+ expect(result.error).toBeUndefined();
44
+ expect(result.status).toBe(0);
45
+ return fs.readFileSync(outputFile, 'utf8');
46
+ }
47
+
48
+ [
49
+ { args: [], forwarded: [] },
50
+ { args: ['build'], forwarded: ['build'] }
51
+ ].forEach(function(testCase) {
52
+ it('warns before forwarding ' + (testCase.args[0] || 'the default command'), function() {
53
+ var output = run(['purgetss'].concat(testCase.args));
54
+ expect(output).toMatch(/alloy purgetss.*deprecated/i);
55
+ expect(output).toMatch(/purgetss --help/);
56
+ expect(output.indexOf('deprecated')).toBeLessThan(output.indexOf('PurgeTSS test executable ran'));
57
+ var calls = fs.readFileSync(callsFile, 'utf8').trim().split('\n').map(JSON.parse);
58
+ expect(calls).toEqual([testCase.forwarded]);
59
+ });
60
+ });
61
+
62
+ it('marks the shortcut deprecated in the command list', function() {
63
+ var output = run(['--help']);
64
+ expect(output).toMatch(/purgetss[^\n]*[Dd]eprecated/);
65
+ expect(fs.existsSync(callsFile)).toBe(false);
66
+ });
67
+
68
+ it('directs command help to the standalone CLI without running it', function() {
69
+ var output = run(['purgetss', '--help']);
70
+ expect(output).toMatch(/deprecated/i);
71
+ expect(output).toMatch(/purgetss --help/);
72
+ expect(fs.existsSync(callsFile)).toBe(false);
73
+ });
74
+ });
@@ -0,0 +1,94 @@
1
+ var fs = require('fs'),
2
+ path = require('path'),
3
+ vm = require('vm'),
4
+ _ = require('lodash'),
5
+ TU = require('../lib/testUtils');
6
+
7
+ var TIMEOUT_COMPILE = 20000;
8
+ var TIMEOUT_PREP = 30000;
9
+ var APP = 'testing/require-conditional-children';
10
+
11
+ // Runs the generated index controller with just enough of Alloy and Titanium stubbed to see
12
+ // which children each <Require> receives.
13
+ function runIndexController(cfg) {
14
+ var file = path.join(TU.paths.harness, 'Resources', 'android', 'alloy', 'controllers', 'index.js');
15
+ var created = {};
16
+ var alloy = {
17
+ _: _,
18
+ Backbone: {},
19
+ CFG: cfg,
20
+ createController: function(name, args) {
21
+ if (args && args.id) {
22
+ created[args.id] = args;
23
+ }
24
+ return {
25
+ getViewEx: function() { return { controller: name }; },
26
+ setParent: function() {}
27
+ };
28
+ }
29
+ };
30
+ var baseController = function() {
31
+ this.__views = {};
32
+ this.addTopLevelView = function() {};
33
+ };
34
+ var sandbox = {
35
+ module: { exports: {} },
36
+ require: function(name) {
37
+ return /BaseController$/.test(name) ? baseController : alloy;
38
+ },
39
+ Ti: {
40
+ UI: {
41
+ createWindow: function() { return { open: function() {} }; },
42
+ createLabel: function(props) { return props; }
43
+ }
44
+ }
45
+ };
46
+ vm.runInNewContext(fs.readFileSync(file, 'utf8'), sandbox, file);
47
+ new sandbox.module.exports();
48
+
49
+ // name each child passed to a <Require>: a controller by its name, a label by its text
50
+ return _.mapValues(created, function(args) {
51
+ return args.children && _.map(args.children, function(child) {
52
+ return child.controller || child.text;
53
+ });
54
+ });
55
+ }
56
+
57
+ describe('<Require> children', function() {
58
+ it('preparing test app', function() {
59
+ TU.asyncExecTest('jake app:setup dir=' + APP + ' quiet=1', { timeout: TIMEOUT_PREP });
60
+ });
61
+
62
+ it('compiles without critical error', function() {
63
+ TU.asyncExecTest('alloy compile ' + TU.paths.harness + ' --config platform=android', {
64
+ test: function() {
65
+ if (this.output.error) {
66
+ console.error(this.output.stderr);
67
+ console.log(this.output.stdout);
68
+ }
69
+ expect(this.output.error).toBeFalsy();
70
+ },
71
+ timeout: TIMEOUT_COMPILE
72
+ });
73
+ });
74
+
75
+ it('does not reference a child whose condition is false', function() {
76
+ var created;
77
+ expect(function() {
78
+ created = runIndexController({ showBadge: false });
79
+ }).not.toThrow();
80
+ expect(created.cardWithoutChildren).toEqual([]);
81
+ expect(created.cardWithChild).toEqual(['badge']);
82
+ });
83
+
84
+ it('passes a child whose condition is true', function() {
85
+ var created = runIndexController({ showBadge: true });
86
+ expect(created.cardWithoutChildren).toEqual(['badge', 'label']);
87
+ expect(created.cardWithChild).toEqual([]);
88
+ });
89
+
90
+ it('passes unconditional children as before', function() {
91
+ var created = runIndexController({ showBadge: false });
92
+ expect(created.cardWithLabel).toEqual(['label']);
93
+ });
94
+ });
@@ -0,0 +1,271 @@
1
+ var path = require('path'),
2
+ _ = require('lodash'),
3
+ U = require('../../Alloy/utils'),
4
+ styler = require('../../Alloy/commands/compile/styler');
5
+
6
+ var fixtureTss = path.join(__dirname, '..', 'apps', 'testing', 'multi-classes', 'styles', 'index.tss');
7
+
8
+ // return only the entries whose key matches
9
+ function byKey(sorted, key) {
10
+ return _.filter(sorted, { key: key });
11
+ }
12
+
13
+ describe('styler.js', function() {
14
+ // U.die() calls process.exit(), which would abort the whole test run.
15
+ // Stub it so an invalid selector surfaces as a failed spec instead.
16
+ var originalDie, died;
17
+
18
+ beforeEach(function() {
19
+ died = [];
20
+ originalDie = U.die;
21
+ U.die = function(msg) {
22
+ died.push(msg);
23
+ throw new Error(msg);
24
+ };
25
+ });
26
+
27
+ afterEach(function() {
28
+ U.die = originalDie;
29
+ });
30
+
31
+ describe('sortStyles() with comma-separated selectors', function() {
32
+
33
+ it('creates one entry per class in ".a, .b"', function() {
34
+ var sorted = styler.sortStyles({ '.a, .b': { color: 'red' } });
35
+ expect(sorted.length).toBe(2);
36
+
37
+ var a = byKey(sorted, 'a')[0];
38
+ var b = byKey(sorted, 'b')[0];
39
+ expect(a).toBeDefined();
40
+ expect(b).toBeDefined();
41
+ expect(a.isClass).toBe(true);
42
+ expect(b.isClass).toBe(true);
43
+ expect(a.style).toEqual({ color: 'red' });
44
+ expect(b.style).toEqual({ color: 'red' });
45
+ });
46
+
47
+ it('creates one entry per id in "#x, #y"', function() {
48
+ var sorted = styler.sortStyles({ '#x, #y': { top: 1 } });
49
+ expect(sorted.length).toBe(2);
50
+ expect(byKey(sorted, 'x')[0].isId).toBe(true);
51
+ expect(byKey(sorted, 'y')[0].isId).toBe(true);
52
+ expect(byKey(sorted, 'x')[0].style).toEqual({ top: 1 });
53
+ expect(byKey(sorted, 'y')[0].style).toEqual({ top: 1 });
54
+ });
55
+
56
+ it('keeps the selector type of each part in a mixed key', function() {
57
+ var sorted = styler.sortStyles({ 'Label, .btn, #main': { width: 100 } });
58
+ expect(sorted.length).toBe(3);
59
+
60
+ var label = byKey(sorted, 'Label')[0];
61
+ var btn = byKey(sorted, 'btn')[0];
62
+ var main = byKey(sorted, 'main')[0];
63
+
64
+ expect(label.isApi).toBe(true);
65
+ expect(label.isClass).toBeUndefined();
66
+ expect(label.isId).toBeUndefined();
67
+
68
+ expect(btn.isClass).toBe(true);
69
+ expect(btn.isApi).toBeUndefined();
70
+ expect(btn.isId).toBeUndefined();
71
+
72
+ expect(main.isId).toBe(true);
73
+ expect(main.isApi).toBeUndefined();
74
+ expect(main.isClass).toBeUndefined();
75
+ });
76
+
77
+ it('gives the API entry a lower priority than the class and id entries', function() {
78
+ var sorted = styler.sortStyles({ '#main, .btn, Label': { width: 100 } });
79
+ expect(sorted[0].key).toBe('Label');
80
+ expect(sorted[1].key).toBe('btn');
81
+ expect(sorted[2].key).toBe('main');
82
+ });
83
+
84
+ it('preserves declaration order between selectors of the same key', function() {
85
+ var sorted = styler.sortStyles({ '.first, .second, .third': { top: 0 } });
86
+ expect(_.map(sorted, 'key')).toEqual(['first', 'second', 'third']);
87
+ expect(sorted[0].priority < sorted[1].priority).toBe(true);
88
+ expect(sorted[1].priority < sorted[2].priority).toBe(true);
89
+ });
90
+
91
+ it('does not split on commas inside a query bracket', function() {
92
+ var sorted = styler.sortStyles({ '.c[platform=ios,android]': { z: 1 } });
93
+ expect(sorted.length).toBe(1);
94
+ expect(sorted[0].key).toBe('c');
95
+ expect(sorted[0].queries).toEqual({ platform: ['ios', 'android'] });
96
+ });
97
+
98
+ it('splits selectors with queries and keeps the query on its own selector only', function() {
99
+ var sorted = styler.sortStyles({ '.x[platform=ios], .y': { z: 1 } });
100
+ expect(sorted.length).toBe(2);
101
+
102
+ var x = byKey(sorted, 'x')[0];
103
+ var y = byKey(sorted, 'y')[0];
104
+ expect(x.queries).toEqual({ platform: ['ios'] });
105
+ expect(y.queries).toBeUndefined();
106
+ expect(x.style).toEqual({ z: 1 });
107
+ expect(y.style).toEqual({ z: 1 });
108
+ });
109
+
110
+ it('handles a bracketed query with a comma next to a plain selector', function() {
111
+ var sorted = styler.sortStyles({ '.a[platform=ios,android], .b[formFactor=handheld]': { z: 1 } });
112
+ expect(sorted.length).toBe(2);
113
+ expect(byKey(sorted, 'a')[0].queries).toEqual({ platform: ['ios', 'android'] });
114
+ expect(byKey(sorted, 'b')[0].queries).toEqual({ formFactor: 'handheld' });
115
+ });
116
+
117
+ it('ignores a trailing comma', function() {
118
+ var sorted = styler.sortStyles({ '.a,': { q: 1 } });
119
+ expect(sorted.length).toBe(1);
120
+ expect(sorted[0].key).toBe('a');
121
+ });
122
+
123
+ it('ignores a trailing comma followed by whitespace', function() {
124
+ var sorted = styler.sortStyles({ '.a, ': { q: 1 } });
125
+ expect(sorted.length).toBe(1);
126
+ expect(sorted[0].key).toBe('a');
127
+ });
128
+
129
+ it('ignores empty chunks between commas', function() {
130
+ var sorted = styler.sortStyles({ '.a,,.b, , .c': { q: 1 } });
131
+ expect(_.map(sorted, 'key')).toEqual(['a', 'b', 'c']);
132
+ });
133
+
134
+ it('trims whitespace around each selector', function() {
135
+ var sorted = styler.sortStyles({ ' .a ,\t.b\n, #c ': { q: 1 } });
136
+ expect(_.map(sorted, 'key')).toEqual(['a', 'b', 'c']);
137
+ });
138
+
139
+ it('gives each selector from one key its own style object', function() {
140
+ var sorted = styler.sortStyles({ '.a, .b': { color: 'red', font: { fontSize: 12 } } });
141
+ var a = byKey(sorted, 'a')[0];
142
+ var b = byKey(sorted, 'b')[0];
143
+
144
+ expect(a.style).not.toBe(b.style);
145
+ expect(a.style.font).not.toBe(b.style.font);
146
+
147
+ a.style.color = 'blue';
148
+ a.style.font.fontSize = 20;
149
+ expect(b.style.color).toBe('red');
150
+ expect(b.style.font.fontSize).toBe(12);
151
+ });
152
+
153
+ it('does not mutate the original style object when a key is split', function() {
154
+ var original = { '.a, .b': { color: 'red' } };
155
+ var sorted = styler.sortStyles(original);
156
+ sorted[0].style.color = 'blue';
157
+ expect(original['.a, .b'].color).toBe('red');
158
+ });
159
+
160
+ it('still reuses the style object for a single selector', function() {
161
+ var style = { color: 'red' };
162
+ var sorted = styler.sortStyles({ '.a': style });
163
+ expect(sorted.length).toBe(1);
164
+ expect(sorted[0].style).toBe(style);
165
+ });
166
+
167
+ it('leaves single selectors untouched next to comma-separated keys', function() {
168
+ var sorted = styler.sortStyles({
169
+ '.a, .b': { color: 'red' },
170
+ '#x': { w: 1 },
171
+ 'Label': { h: 2 }
172
+ });
173
+ expect(sorted.length).toBe(4);
174
+ expect(_.map(sorted, 'key')).toEqual(['Label', 'a', 'b', 'x']);
175
+ });
176
+
177
+ it('appends split entries to an existing style', function() {
178
+ var existing = styler.sortStyles({ 'Label': { h: 2 } });
179
+ var sorted = styler.sortStyles({ '.a, .b': { color: 'red' } }, { existingStyle: existing });
180
+ expect(sorted.length).toBe(3);
181
+ expect(_.map(sorted, 'key')).toEqual(['Label', 'a', 'b']);
182
+ });
183
+
184
+ it('applies platform and theme priority bumps to every split entry', function() {
185
+ var plain = styler.sortStyles({ '.a, .b': { q: 1 } });
186
+ var bumped = styler.sortStyles({ '.a, .b': { q: 1 } }, { platform: 'ios', theme: 'dark' });
187
+ _.each(bumped, function(entry, i) {
188
+ // ORDER increments are tiny (0.0001 per entry), the platform+theme
189
+ // bump is 100.9, so a > comparison is enough here
190
+ expect(entry.priority - plain[i].priority > 100).toBe(true);
191
+ });
192
+ });
193
+
194
+ describe('invalid selectors', function() {
195
+ it('dies on an invalid part of a comma-separated key', function() {
196
+ expect(function() {
197
+ styler.sortStyles({ '.a, [broken': { q: 1 } });
198
+ }).toThrow();
199
+ expect(died.length).toBe(1);
200
+ expect(died[0]).toBe('Invalid style specifier "[broken"');
201
+ });
202
+
203
+ it('does not die on a whitespace-only part after a trailing comma', function() {
204
+ expect(function() {
205
+ styler.sortStyles({ '.a, ': { q: 1 } });
206
+ }).not.toThrow();
207
+ expect(died.length).toBe(0);
208
+ });
209
+ });
210
+ });
211
+
212
+ describe('loadStyle() + sortStyles() from a .tss file', function() {
213
+ var sorted;
214
+
215
+ it('loads the multi-classes fixture', function() {
216
+ var loaded = styler.loadStyle(fixtureTss);
217
+ expect(_.isObject(loaded)).toBe(true);
218
+ expect(loaded['#header, #footer']).toBeDefined();
219
+ expect(loaded['.heading, Button']).toBeDefined();
220
+ sorted = styler.sortStyles(loaded);
221
+ });
222
+
223
+ it('expands "#header, #footer" into two id entries', function() {
224
+ var header = byKey(sorted, 'header');
225
+ var footer = byKey(sorted, 'footer');
226
+ expect(header.length).toBe(1);
227
+ expect(footer.length).toBe(1);
228
+ expect(header[0].isId).toBe(true);
229
+ expect(footer[0].isId).toBe(true);
230
+ expect(header[0].style).toEqual(footer[0].style);
231
+ expect(header[0].style).not.toBe(footer[0].style);
232
+ });
233
+
234
+ it('expands ".heading, Button" into a class and an API entry', function() {
235
+ var heading = byKey(sorted, 'heading');
236
+ var button = byKey(sorted, 'Button');
237
+ expect(heading.length).toBe(1);
238
+ expect(button.length).toBe(1);
239
+ expect(heading[0].isClass).toBe(true);
240
+ expect(button[0].isApi).toBe(true);
241
+ expect(heading[0].style.top).toBe(10);
242
+ expect(button[0].style.top).toBe(10);
243
+ });
244
+
245
+ it('keeps ".button[platform=ios,android]" as a single entry', function() {
246
+ var buttons = byKey(sorted, 'button');
247
+ var withQuery = _.filter(buttons, function(b) { return b.queries; });
248
+ expect(withQuery.length).toBe(1);
249
+ expect(withQuery[0].queries).toEqual({ platform: ['ios', 'android'] });
250
+ expect(withQuery[0].style).toEqual({ width: 200 });
251
+ });
252
+
253
+ it('applies the query only to ".muted" in ".muted[platform=ios], #secondary"', function() {
254
+ var muted = byKey(sorted, 'muted')[0];
255
+ var secondary = byKey(sorted, 'secondary')[0];
256
+ expect(muted.queries).toEqual({ platform: ['ios'] });
257
+ expect(secondary.queries).toBeUndefined();
258
+ expect(muted.style).toEqual({ opacity: 0.5 });
259
+ expect(secondary.style).toEqual({ opacity: 0.5 });
260
+ });
261
+
262
+ it('ignores the trailing comma in ".button,"', function() {
263
+ var plain = _.filter(byKey(sorted, 'button'), function(b) { return !b.queries; });
264
+ expect(plain.length).toBe(1);
265
+ expect(plain[0].style).toEqual({ height: 44 });
266
+ // no entry was created for an empty selector
267
+ expect(byKey(sorted, '').length).toBe(0);
268
+ expect(byKey(sorted, 'undefined').length).toBe(0);
269
+ });
270
+ });
271
+ });